The layout of our application is as follows
WCF - Business Layer class library dll - Data Access Layer class library dll - SQL Server.
Generally the class libraries do not access external resources other than the DB.
The WCF layer delivers data for reports.
Having seen some guidance that exceptions should be handled in the upper level I guess this means that I could simply let the class libraries throw the exceptions and so I do not need any try catch statements in the class libraries what so ever!
I feel the don't need to catch exceptions and log specific info in the library and plan to catch exceptions in the app/client code which in this case is the WCF layer. WCF Exception Handling Strategies
At this level I plan to log the exception/stacktrace and present a user friendly exception.
I feel that logging the stack trace at WCF level will give me enough info to determine the cause of the issue and also.
Is this an OK approach or have I missed something
I wish to keep it simple, avoid unnecessary try catches and handle exceptions/log in one location only.
Eric Lippert has written a good article on Exception Handling. I suggest you might take a look.
Unless you can absolutely do something, you might catch any exception so that you can try something else to avoid it. If there's no way you may avoid it, then let's hope for the best with the finally block. Otherwise, IMHO, it is best to let the exception bubble up and handle it there, since you "don't know" what will really consume your service, so I think your service shall let any exception bubble up and let the end-user decide what to do with it, as everyone will not handle these the same.
Again, from an Eric Lippert's blog which I can't find the URL right now, it is best to write code such as:
if (someUncoverableCondition)
throw new SomeSpecificException();
than trying to catch every exception possible.
In the end, handle what you can and what you know how to handle, and let the other exceptions occur. Perhaps after a while you'll know how to handle those exception in an efficient way so that you can refactor your code. Meanwhile, if you feel like it's perhaps better to let them through, that must be the right thing to do in your situation.
Here's further reading.
The Bad Practices of Exception Handling (Perhaps not directly related, but good to know anyway)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With