Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Global Error Handling
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00860796
Message ID:
00861063
Vues:
25
>Has anyone come across articles, links, books, etc - that provide more in-depth information on this topic?

By "global", I'm assuming that you mean the last-resort, if-everything-else-fails error handling.

Jim Duffy had a good article on ASP.NET error handling in a recent CoDe magazine article, that demonstrates some specific techniques that I found useful. Rick Strahl has a fairly robust error handling class in his WebStore product.

I took some things that I learned from Mr. Duffy, put 'em together with some things that came out in a thread w/Mr. Strahl here, and developed an error handling class that can work in either the ASP.NET or WinForms environment.

My basic approach in a WinForms app is to wrap a structured TRY...CATCH block around the instantiation of my application or other top-level object. If an unhandled exception is caught by this block, it simply instantiates the global error handling class and passes the exception to that class, which knows how to either log the error to an XML file or the Event Log (for postmortem) and/or email the error details to someone.

Similarly, any un-anticipated or fatal error detected by any other TRY...CATCH can either re-throw the exception, or can do the same thing as my top-level TRY...CATCH. The end result is the same, though handling it directly ensure that the error isn't handled by a higher-level, but not "global" TRY...CATCH block.

Note that if you're not interested in logging error information, you don't need an error handling class. Just tell the user that "something bad" happened and terminate the app.

As a Caveat Emptor Al, keep in mind that my error handling class is only in use in a production ASP.NET app - I'm still working on my first production WinForms app, so all this advice is worth every penny you paid for it <g>.

Here's a simple example of what I'm doing:
static void Main() 
{
   try
   {
      Application.Run(new TopLevelForm());
   }
   catch (Exception e)
   {
      if (e.InnerException == null)
         MessageBox.Show(e.Message);
      else
         MessageBox.Show(e.InnerException.Message);
   }
}
Obviously, you wouldn't just spit up a messagebox, but at the point that the sample above is doing so, you can do whatever is appropriate. My code informs the user of a problem, instantiates the error handler to log the error and the app terminates.
>>-Steve->>

Steve Sawyer
Geeks and Gurus, Inc.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform