Hi

Sorry, but remark in MSDN for AppDomain.UnhandledException:

This event occurs only for the application domain that is created by the
system when an application is started. If an application creates
additional application domains, specifying a delegate for this event in
those applications domains has no effect.

What can I do in manually created appdomain?

--
Andrey Shvydky

> -----Original Message-----
> From: Ayyappan Nair [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 28, 2003 1:33 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] Which way is the better way to
> trap all unexpected exception !
>
>
> Hi,
>
> Any Unhandled Exception will generate an UnhandledException
> Event and this
> can be trapped by the UnhandledExceptionEventHandler
> delegate. The method
> associated with the delegate will be executed every time an Unhandled
> Exception occurs. Inside this method you can do any
> processing you want like
> your BugTracking.LogException(ex); and maybe inform the user
> that a fatal
> error occurred and then exit the application.
>
> Whether the application should terminate or user should be allowed to
> continue after an exception, depends on the kind of Exception
> being thrown.
> I think you should have separate catch blocks for the kind of
> exceptions
> that can be identified as not fatal and allow the user to
> continue with the
> application. The catch filter should be based on the type of
> exceptions
> likely in the try block. Regarding Application.Exit(), this
> will terminate
> only the current thread. So if it's called in any other
> thread other than
> the Main thread, only that thread will terminate, but the
> main thread will
> continue to execute. You might want to use Environment.Exit()
> to terminate
> the application caused by a fatal error from any thread.
>
> [STAThread]
> static void Main()
> {
>         AppDomain.CurrentDomain.UnhandledException += new
> UnhandledExceptionEventHandler(UnhandledHandler);
>         try
>         {
>                 string
> strConnect="Provider=Microsoft.Jet.OLEDB.4.0;Data
>                         Source=db.mdb;Persist            Security
> Info=False;";
>         OleDbConnection conn=new OleDbConnection(strConnect);
>             conn.Open();
>             Application.Run(new MainForm(conn));
>         }
>         catch(SystemException ex)
>         {
>                 BugTracking.LogException(ex);
>                 Application.Exit();
>         }
> }
>
> static void UnhandledHandler (Object sender,
> UnhandledExceptionEventArgs e)
> {
>         //Inform user of a fatal error
>         //Maybe MessegeBox.Show
>         BugTracking.LogException(ex);
>         Environment.Exit();
> }
>
> HTH,
> Ayyappan Nair

Reply via email to