Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multi-Project Exception Handling
Message
De
08/06/2009 14:07:09
 
 
À
08/06/2009 13:23:48
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01404075
Message ID:
01404523
Vues:
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
>
Hi,
I did it in XAML:
<Application x:Class=“Whatever.App”
    xmlns=“http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml”
    StartupUri=“MainWindow.xaml”
    DispatcherUnhandledException=“HandleUnHandled”>
</Application>
But you're right - better to not use it in Debug mode......
Are you doing much WPF currently?
I've been pretty immersed in WPF for the last three/four weeks and like it more all the time. Wouldn't go back to Winforms if they paid me (well, I suppose I would but I'd rather not <g>)
Finally got a real handle on DependencyObjects and, after implementing a few, a better understanding of the benefits of attached properties....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform