Code Elegance

Exception Bubbling

Often in class during lesson people find difficult to understand how to manage the exception in a real word application.
Think about a 3 layer application (UI, Biz, DAL), the question is always: “How do I manage the DAL exception? Should I intercept the exception in the DAL and return an error code to the caller? Should I let the exception raise in the business layer? Should I catch the exception and rethrow it to the caller?

I try varius way but today the best one is:
1) Catch the exception in the DAL and rethrow a new custom exception (MyDalExcetion)
2) In the business layer catch the MyDalExcetion and throw a MyBizException to the UI Layer which can handle it and eventually show an error message to the user

It’s not always true that an exception has to be rethrow, should exists cases in which a layer can solve the problem by itself.

Posted in Emanuele DelBono | No comments

No comments yet. Be the first.

Leave a reply

Spam Protection by WP-SpamFree