Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multi-Project Exception Handling
Message
From
08/06/2009 13:23:48
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01404075
Message ID:
01404513
Views:
30
>>I have a solution with multiple projects in it. How do I do exception handling so that all exceptions from any project in the solution are handled in one place?
>
>Depends on whether this is Winforms, ASP.NET or WPF. Assuming Winforms then just handle the ThreadException event in main:
>[STAThread] static void Main()
> {
>  Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Root_Exception);
>  Application.Run(new MainWindow());
>}
>private static void Root_Exception(object sender, System.Threading.ThreadExceptionEventArgs e)
> {
>  //Handle exception here.  
>}
But it's not good design to let most exceptions get this far. If you have a project that is likely to generate a specific exception it should be caught there. If it can't be handled then it can be re-thrown.....
>
>Also bear in mind that the ThreadException will only fire for exceptions in the main thread.....
>HTH,
>Viv

For WPF I use:
#if !DEBUG  // Don't use in debug mode.
  Application.Current.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
#endif
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform