Well we all have been handling Exceptions in our programs for exception scenarios. But are we doing it right?

Here are the following rules, which I definitely feel should be followed in process of handling any exception

Dont generalize exceptions

Do not create a single top level custom Exception which does the whole exception handling task. Learn from API designers of JAVA programming language.

Identify exceptions at least granular level

Try to identify exceptions at least meaningful level so that exceptions are clearly and precisely identified. Do remember one thing, a granular thing can be coalesced but a coalesced thing cannot be granularized in programming.

Give exceptions some codes while dealing at service layer

Exceptions can be assigned codes similar to HTTP status codes, which eventually helps client to understand the error.

Log exceptions beautifully

Exceptions should be logged in a beautiful manner, so that maximum information can be extracted from logged information.