Throwing Exceptions & Catching Exceptions

Onur AKAN
Oct 16, 2020

I came a cross with this question lately in a tough software project: How to throw self explanatory exception? Our exceptions arent understood when it comes to detect an error in log files or even during debugging.

Our service callers, namely clients, are not interested how our service is implemented in general. Therefore what we are doing in implementation should not be propagated to out side world. If there is a 3rd service we are calling in our implementation, that service exceptions should not be thrown to outside world. Our clients may not be ready to catch them. It is like saying them “Catch I have a new exception which you have never saw before” when they turn about.

So what to do then? Don’t throw an exception before handshaking with your clients and don’t throw an exception if it is not yours. If there is an exception inside 3rd service catch it and throw your original service exception. You can guarantee that your client recognize that exception, because it is already in their catch block.

“Don’t bother your client with your own problems”

Take care;
oa

--

--