locked
Comment on my exception handling structure needed RRS feed

  • Question

  • Please give me some comments on my existing exception handling design.

    1. I use the Exception handling application block from Enterprise Library 3.1 (EntLib)
    2. I use the ExceptionHandler only in the Application event "UnhandledException"
    3. I defined some custom exceptions that are inherited from the ApplicationException. For each custom exception, I also defined custom exception handler for the usage in EntLib
    4. The application code will raise different custom exceptions when necessary.
    5. There is only 1 exception policy in my config. The policy will call respective handler for each exception type
    6. I added logging to some type of exceptions when necessary. (Main purpose is to store stack trace to event log)
    7. I define the policy of some exception type to rethrow the exception. However, this will cause the code in the application event handler quit the application. (Anyway, I don't have any means to let user recover from those exceptions.)

    The above is a brief description of my current setup. Please comment on this approach of handling exception.

    Pros:
    I don't need to add try ... catch block in each event handling function of my Windows Forms.
    Code is simple. Just a single piece of code in the application event
    I can get a stack trace on all unhandled exception. (Actually, all exceptions are not handled in the application code now.)

    Cons:
    Please suggest.
    Thursday, August 9, 2007 2:47 PM

Answers

  • Hi Alex,

     

       seems like your structure is fine

     

       Just in case you didn't, I always recommend Krzysztof Cwalina's talk on "Designing .NET Class Libraries"

     

       It's a session of about 4 hours (relax, continue reading ) on designing frameworks by examples taken from how the .NET class library was designed and implemented

     

       If you click on that session and go directly to the 2:23 (two hours, twenty three minutes) in the timeline, Krysztof starts talking about the good, bad and ugly of exceptions and how to use them wisely

     

       Cwalina was the architect of the .NET base class library and he wrote a book on designing frameworks

    Monday, August 20, 2007 9:18 PM

All replies

  • Let me give more input to my own architecture.

    Cons:
    1. It's slow to startup the EntLib. This becomes a particular problem to my situation as I'm required to run the program on a Celeron 1.XG machine with 256M RAM only. Moreover, WinXP is used. It takes around 15~20 seconds for the first call to EntLib.
    Wednesday, August 15, 2007 2:36 AM
  • Hi,

     

    So you are going for a 'fail fast' approach to exception handling where you only have a single exception handler at the highest level, I presume then you are expecting the user to restart the application if an exception occurs and the startup time of application is what concerns you at the moment. What calls are you making to ent. lib. and are the ent. lib. assemblies being dynamically loaded at all?

     

    Ollie Riches

    Wednesday, August 15, 2007 8:42 AM
  • Hi Ollie,

    Actually, I assume the user will contact the support and the bug report will go to me afterwards if they hit any exception. I can't think out any exception that can be resolved simply by restarting the program. The cause of exception should be something like program bug and mis-configuration. Users won't have any mean to fix these problems on their own.

    For EntLib, I only call the ExceptionPolicy.HandleException. This call takes me up to 20 seconds in the slow PC. However, I have no idea on dynamically loading of EntLib. Are there some configurations that I have missed out?

    Regards,
    Alex
    Wednesday, August 15, 2007 10:00 AM
  • I preume your program has a static reference to the ent lib assemlbies - you will know this by checking to see if there is a reference to the ent. lib. assemblies inside visual studio in your project references folder.

     

    Have you run a performance profiler over the application?  check out something like Ants Profiler.

     

    HTH

     

    Ollie Riches

     

    Wednesday, August 15, 2007 3:01 PM
  • Hi Alex,

     

       seems like your structure is fine

     

       Just in case you didn't, I always recommend Krzysztof Cwalina's talk on "Designing .NET Class Libraries"

     

       It's a session of about 4 hours (relax, continue reading ) on designing frameworks by examples taken from how the .NET class library was designed and implemented

     

       If you click on that session and go directly to the 2:23 (two hours, twenty three minutes) in the timeline, Krysztof starts talking about the good, bad and ugly of exceptions and how to use them wisely

     

       Cwalina was the architect of the .NET base class library and he wrote a book on designing frameworks

    Monday, August 20, 2007 9:18 PM
  • Thanks Diego,

    I think it really gives some answers to my concerns.

    Regards,
    Alex
    Tuesday, August 21, 2007 8:31 AM