Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to catch exceptions

I have a WCF svc separated into a Service Layer, Business Logic Layer and Data Access Layer.

When my DAL encounters an exception, should I catch it there or let it bubble back up to the Service Layer? And why?

Please disregard any client involvement for this scenario, I am only concerned with logging the exceptions on the WCF svc.

like image 337
mcass20 Avatar asked Dec 23 '22 01:12

mcass20


1 Answers

There is a term for that - Exception Shielding. Basically you should prevent SYSTEM exceptions to travel to higher level, because this could give an atacker a view of your system architecture. WCF Exception Shielding can catch exceptions of certain type and replace them with exceptions of other type. For example it could catch StackOverflow exception and replace it with your custom SystemException. If you use Enterprise Library you could also configure to log these exceptions when they are replaced

Using the Exception Handling Block in Enterprise Library 3.0

like image 184
Sergej Andrejev Avatar answered Jan 06 '23 22:01

Sergej Andrejev