Harkos,
Wrapping your Application.Run method with a Try/Catch block will not catch
unhandled exceptions.
The events occur asynchronously, in response to mouse clicks & other user or
system actions, if you were to catch these after Application.Run your app
would have stopped running (Application.Run is a 'Message Pump' loop, you
do not want that loop to exit, unless you are exiting your app).
If you want to avoid the window that says there was an unhandled exception,
you can use global exception handlers in your .NET app.
Depending on the type of application you are creating, .NET has three
different global exception handlers.
For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.
For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.
For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.
In stead of the do try/catch loop, simply handle the
Application.ThreadException event before calling other methods on
Application.
Hope this helps
Jay
> I'm currently trying to make my application restart when an unhandled
> exception gets through to the Main call. It does something like this:
[quoted text clipped - 15 lines]
> []'s,
> Harkos
Harkos - 28 Jul 2003 18:22 GMT
Hi Jay,
I'm developing a Windows Form application. What I'm trying to create is the
same thing that happens with MSIE when a huge error happens. I'd rather
really close the entire app and restart it to avoid creating a much bigger
problem to the user. So I don't simply want to handle the exception, but
also restart the application and check if the user wants to send me a report
about the error.
Another thing, why my code runs correctly on Win2K Server?
[]'s,
Harkos
> Wrapping your Application.Run method with a Try/Catch block will not catch
> unhandled exceptions.
[quoted text clipped - 7 lines]
> System.Windows.Forms.Application.ThreadException event
> Use AddHandler in your Sub Main.
Jay B. Harlow [MVP - Outlook] - 29 Jul 2003 15:31 GMT
Harkos,
> Another thing, why my code runs correctly on Win2K Server?
Not sure.
> So I don't simply want to handle the exception, but
> also restart the application and check if the user wants to send me a report
> about the error.
I would not put the Application.Run in simple loop as you did then. I would
actually create new AppDomain and really restart the "app". This is what
ASP.NET does. Unfortunately I do not have a specific example of this. You
might start here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conapplicationdomains.asp
As simply restarting Application.Run, you will still have objects in memory
that you are using, static/shared variables & such. Where as creating a new
AppDomain will cause all objects to be created fresh.
The next level of isolation would be to actually restart the app. Actually
have 2 programs. The 'monitor' that uses Process.Start to start the actual
app. If the monitor decides the actual app failed, it would use
Process.Start to physically restart the app.
Hope this helps
Jay
> Hi Jay,
>
[quoted text clipped - 22 lines]
> > System.Windows.Forms.Application.ThreadException event
> > Use AddHandler in your Sub Main.