The surprising thing is that this works in VS.NET - you should really be
trapping the Application.ThreadException event - this is raised by Windows
Forms when an event handler throws an exception.
As for why throwing an exception in your form constructor is
different...well it could be this: are you throwing the exception from the
main form? Remember that Windows Forms apps usually start like this:
static void Main()
{
Application.Run (new Form1());
}
If Form1's constructor throws an exception, the call to Application.Run will
never happen. This means that Windows Forms' exception handling has not yet
come into play. But by the time a click handler is called you are
definitely in a world controlled by Windows Forms, so everything is
different.
Could you be more specific about "Does Not Work" - what happens? Does your
app exit silently? Does nothing happen at all?
--
Ian Griffiths
DevelopMentor
----- Original Message -----
From: "Paul Stevens" <[EMAIL PROTECTED]>
> I have run into e few strange problems when using different methods to
> handle "unhandled" exceptions
>
> I have tried catching all unhandled exceptions in the following two ways
>
> 1. Put a try Catch Block around Application.Run
> 2. Use The Appdomain's Unhandled Exception Event
>
> Both of these work great while I am running my code using VS but the
moment
> I Compile and run the exe these stop working in both cases it is as if the
> code does not exist
>
> Upon further testing I found the following strange behaviour in the
Compiled
> Versions Both Debug and release builds have the same behaviour, if a throw
> an exception in sub new of a form without handling it the unhandled
> exception event is triggered and everything works fine, if however I throw
> the same exception in the click event of a button its Does Not work, Keep
in
> mind that when running this from VS it all works flawlessly. I am
obviously
> doing something wrong but what?
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.