catch (Exception e) in entlib error handler?

Topics: Building and extending application blocks, Exception Handling Application Block
Jan 10, 2012 at 7:51 AM



Please pardon me if I'm sounding dumb. I'm very new to entlib and have a basic doubt.

we always learnt catching exception of type root object "Exception" is a bad practice. 

but every example I see, they have written




catch(Exception e) // is this a good practice?


//use entlib exception block.


Please help. 


Jan 11, 2012 at 2:18 AM

As in most things, it depends on how you use it.

From the Developer's Guide:

The Exception Handling block was never intended for use everywhere that you catch exceptions. The block is primarily designed to simplify exception handling and exception management at your application or layer boundaries.

So, the intent isn't to wrap everything in a generic try/catch and use the block to handle every possible exception; the intent it to provide a way to centralize and manage exceptions at key places in an application where you want control of how exceptions are exposed and processed.  Typical use cases might be a global error handler in a WinForm application or shielding of sensitive exception information for a WCF service.

Randy Levy
Enterprise Library support engineer