Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multi-Project Exception Handling
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01404075
Message ID:
01404087
Vues:
41
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform