开发者

catch every exception from DAL with another exception

I have an n-tier web application, and I want to catch a specific type of exception in every method coming from the DAL (Data access layer) and rethrow it as a new exception of a specific type.

There are many methods in my DAL, so I 开发者_StackOverflow中文版don't want to start wrapping each one with try/catch.

I think this is possible using the Exception Handling Application Blocks, but i couldn't find any good documentation of how to do this...

I'm not familiar with the previous versions of the application blocks neither.


Has your DAL repositories got an interface? I would implement the interface using a decorator pattern. All the decorator does catches the exception and then builds a new exception and throws that out to the upper tier

As a point of note, in our n-tiered applications we always let exception just get thrown naturally and catch them in once single place and log them. We only create specific exceptions if we absolutely have to and that would be rare enough.

The reason for this is maintainability of code. Code can easily become unreadable when try/catches exist everywhere.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜