Bryce,
>With this code, you will get a messagebox showing the error when run from
>VS. You will not from running outside.
The exception gets caught alright here, running on v1.1 of the
framework.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Bryce Covert - 30 Jun 2005 15:19 GMT
Really? Odd that it doesn't for me. Running straight from the .exe, I get the
exception in the "unhandled exception" messagebox.
I'm running Visual Studio .NET 2003
Any help anyone?
Thanks!
<snip>
> With this code, you will get a messagebox showing the error when run from
> VS. You will not from running outside.
Well, the good news is that it's got nothing to do with running in a
different assembly. The bad news is I don't entirely understand it. I
*believe* it's because when you show a dialog, it starts a new message
pump, and *that's* what is popping up the message box. I don't know how
to solve it though. It might be worth asking in the Windows Forms
newsgroup. Here's the code I used to reproduce it in the end in a more
compact (and readable to me, as a C# programmer :) form:
using System;
using System.Windows.Forms;
public class Test : Form
{
public Test()
{
Load += new EventHandler(LoadEventHandler);
}
private void LoadEventHandler(object sender, EventArgs args)
{
throw new Exception("Hello");
}
static void Main()
{
try
{
new Test().ShowDialog();
}
catch (Exception e)
{
Console.WriteLine ("Caught "+e);
}
}
}

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Mehdi - 01 Jul 2005 22:24 GMT
> Well, the good news is that it's got nothing to do with running in a
> different assembly. The bad news is I don't entirely understand it. I
[quoted text clipped - 3 lines]
> newsgroup. Here's the code I used to reproduce it in the end in a more
> compact (and readable to me, as a C# programmer :) form:
Funny, reading your code i've realized that this is the exact same problem
i ran into last week. Throwing an exception from the Load event handler
results in a weird behaviour in Visual Studio (unhandled exception even
with a try/catch) but runs fine outside VS. So i just assumed that it was a
bug with VS and moved on. But i'd be interested to know what the real
problem is.
Jon Skeet [C# MVP] - 01 Jul 2005 23:51 GMT
> > Well, the good news is that it's got nothing to do with running in a
> > different assembly. The bad news is I don't entirely understand it. I
[quoted text clipped - 10 lines]
> bug with VS and moved on. But i'd be interested to know what the real
> problem is.
That's the opposite behaviour from what's being reported here. I
haven't even run my test program in VS - it's running it from the
command line that I get the message box, and I believe it's running
outside the debugger that the OP is getting problems. Hmm...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Mehdi - 02 Jul 2005 02:02 GMT
>> Funny, reading your code i've realized that this is the exact same problem
>> i ran into last week. Throwing an exception from the Load event handler
[quoted text clipped - 7 lines]
> command line that I get the message box, and I believe it's running
> outside the debugger that the OP is getting problems. Hmm...
Right, i misread the post. Well, in this case, the behaviour i had was
effecively the exact opposite. I'll try to see tomorrow if i kept this bit
of code somewhere in some test project.