Exception Block, when and why should you use it? RRS feed

  • Question

  • Background
    I am fairly new to .net, but am advising my new firm what architectures to follow, as well as putting together an organizational best practice wiki.  To this end I have been researching WPF, WCF, Software factories, Enterprise library etc, etc.

    When looking through the Enterprise Library documentation I decided to prototype the Exception Block (being a pretty strait forward component).  However now I have gone through the process of implementing this Block the obvious question comes to mind, is this actually better than writing an standard exception handling class myself?

    The issues I have are:
    1. The code that I have to write to implement the Exception Block seems to be similar in size to if I wrote a class myself.
    2. There is a bunch of 'guff' that I have to fill in to the .config file in addition to writing the class library
    3. I guess the above points highlight the other issue; I am not sure what application block provides in addition to the exception class that you seem to have to write yourself.

    Or put another way
    Most blogs, tutorials have stated that the Exception block is great because it saves time & uses Microsoft best practise.  Then later when they give code examples, there seems to be a lot of code to write considering the 'reuse', and 'time-saving' statements.  So I would argue that you definatly would not save time over using a very simple exception handling process.  What I think must be missing is the added value of using the exception block. (I am guessing that decoupling is the big advantage thus the 'guff' in the .config file - but it would be nice to have real world examples on how it helps.)

    Here is a link to the tutorial I followed
    Thursday, February 12, 2009 12:34 AM


  • If your application is a multi-layered distributed application, then using exception block would be useful depending on different exception scenarios(policies) instead of just bubbling the exception to the top most layer from the inner most layer.  Take a look at a figure 1 in the link to exception block msdn documentation.  If you are just using simple try,catch and finally blocks and bubble exceptions to upper layers, than this may be a over kill.

    { Gaja; }

    Pl mark if answer solves your problem | Visit http://gajakannan.com/netarch.aspx for .net ref Arch
    Thursday, February 12, 2009 4:25 AM