On of the most discussed software development topics is the right exception handling. Exception handling is one of the basic building blocks of resilience and without any surprise the correct exception handling depends on your application.
But here some well working tips to keep exception handling easy:
- Find out how important is this code place. If you compare it with a car, is it the breaker or is it the seat heating.
- If your code is the "seat heating" category then:
- Catch the exception
- Log the exception as error.
- Maybe count the errors as metric and put the metric on a dashboard.
- If your code is in the "brake" category then
- Maybe catch and log the exception with the context e.g. the related method parameter
- Throw re-throw the exception and handle it on the presentation layer (front end)
- If you can't clearly decide between the categories "seat heating" and "brake"
- handle the exception like category "seat heating"
- create an alert on the metric
- If you have an fallback use the fallback and count the usage via log message or as metric
No comments:
Post a Comment