Click here to Skip to main content
15,891,905 members
Articles / Programming Languages / C#

To Err is Human… to Handle, Divine

Rate me:
Please Sign up or sign in to vote.
3.54/5 (5 votes)
9 Apr 2007CPOL10 min read 36.6K   73   32  
How do you handle exceptions? Do you reuse your solution?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
  <configSections>
    <section name ="errorSubSystem" type ="Jason.EnterpriseErrorHandler.ConfigurationHandler.ErrorSubSystem,
                                           EnterpriseErrorHandler"/>
  </configSections>

  
  <errorSubSystem>

    <!--
    The following Policy will Format all Unhandled Exceptions Verbosly, and log them to a text file.
    Filename, is the path and filename of any desired log file.
    -->
    <add Exception="System.Exception">
      <Formatter type="Jason.EnterpriseErrorHandler.TextFormatter, EnterpriseErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      <Handler type="Jason.EnterpriseErrorHandler.ErrorTextWriter, EnterpriseErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" 
               Filename ="C:\\Logfile.txt"/>
    </add>
    <!--
    The following Policy will Format all Unhandled ArgumentExceptions Verbosly, 
    and log it to UserMessageBox With okay button.
    
    <add Exception="System.ArgumentException">
      <Formatter type="Jason.EnterpriseErrorHandler.TextFormatter, EnterpriseErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      <Handler type="Jason.EnterpriseErrorHandler.ErrorMsgBxWriter, EnterpriseErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    </add>
    -->
    
    <!--
    Clear will remove all existing policies from the policy collection.
    
    <clear/>
    -->
    
    <!--
    The following Policy will Format all Unhandled ArgumentExceptions breifly, 
    and log it to UserMessageBox With okay button.
    -->
    <add Exception="System.ArgumentException">
      <Formatter type="Jason.EnterpriseErrorHandler.UserFormatter, EnterpriseErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      <Handler type="Jason.EnterpriseErrorHandler.ErrorMsgBxWriter, EnterpriseErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
    </add>
    <!--
    The following Policy will Format all Unhandled ArgumentExceptions Verbosly, 
    and log it into the EventHandler under the ErrorSubSystem Node, with a Informational icon.
    EventNode is an arbtray String, but defaulted to the ApplicationNode.
    EventType is is a enumeration which can take the values FailureAudit, Warning, SuccessAudit, Information, Error 
    -->
    <add Exception="System.ArgumentException">
      <Formatter type="Jason.EnterpriseErrorHandler.TextFormatter, EnterpriseErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      <Handler type="Jason.EnterpriseErrorHandler.ErrorEventWriter, EnterpriseErrorHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
               EventNode ="ErrorSubSystem" EventType="Information"/>
      <!-- EventTypes .FailureAudit .Warning .SuccessAudit .Information .Error -->
    </add>

  </errorSubSystem>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Berkeley Grad (B.A. Computer Science) With MBA

Comments and Discussions