Unhandled exception ignored?

S

sb

In the simplified code below, shouldn't the thrown exception cause the app
to terminate since it is unhandled? It doesn't seem to do anything in Debug
or Release mode. I do get a first-chance exception message in the debugger
but that's it. Something seems to be intercepting the exception and
handling it...but I don't know what.

Any info would be appreciated :)
-sb



// Entire program
using System;
using System.Windows.Forms;

static class Program
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}

public class Form1 : Form
{
public Form1()
{
this.AllowDrop = true;
this.DragDrop += new
System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);
this.DragOver += new
System.Windows.Forms.DragEventHandler(this.Form1_DragOver);
}

private void Form1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy; // We'll accept any kind of drop
}

private void Form1_DragDrop(object sender, DragEventArgs e)
{
throw new InvalidOperationException("DragDrop exception."); //
nothing happens here
}
}
 
S

Stoitcho Goutsev \(100\)

DragDrop event called as a result of COM drag and drop operation and is
called directly by COM. If any exception should happen they are probably
re-routed to the caller (which is not your application) and it looks like
they get swallowed.
 
S

sb

Thanks for the reply but what does this have to do with COM? I thought
drag/drop events were just normal windows messages (ie WM_DROPFILES). I'll
have to look into that some more I guess. The wierd part is that if I wrap
the exception in a try/catch block within the Form.DragDrop event, I can
intercept it just like any other exception. I thought another thread might
be handling the exception but the ManagedThreadID within the method is the
same as the rest of the application.

I would like to understand this issue better...I just don't get it :)

-sb


Stoitcho Goutsev (100) said:
DragDrop event called as a result of COM drag and drop operation and is
called directly by COM. If any exception should happen they are probably
re-routed to the caller (which is not your application) and it looks like
they get swallowed.


--
HTH
Stoitcho Goutsev (100)

sb said:
In the simplified code below, shouldn't the thrown exception cause the
app to terminate since it is unhandled? It doesn't seem to do anything
in Debug or Release mode. I do get a first-chance exception message in
the debugger but that's it. Something seems to be intercepting the
exception and handling it...but I don't know what.

Any info would be appreciated :)
-sb



// Entire program
using System;
using System.Windows.Forms;

static class Program
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}

public class Form1 : Form
{
public Form1()
{
this.AllowDrop = true;
this.DragDrop += new
System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);
this.DragOver += new
System.Windows.Forms.DragEventHandler(this.Form1_DragOver);
}

private void Form1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy; // We'll accept any kind of
drop
}

private void Form1_DragDrop(object sender, DragEventArgs e)
{
throw new InvalidOperationException("DragDrop exception."); //
nothing happens here
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top