Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multi-Project Exception Handling
Message
De
08/06/2009 13:23:48
 
 
À
06/06/2009 03:34:22
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01404075
Message ID:
01404513
Vues:
29
>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform