4 ms·
I like to say that the whole point of exceptions is not to handle them -- except when you know exactly which exception can happen and how to handle it. Everythi
by BerislavLopac 3y ago
I like to say that the whole point of exceptions is not to handle them -- except when you know exactly which exception can happen and how to handle it. Everything else should be allowed to bubble up and handle on the highest level, whether it's by returning an error HTTP code, showing an error message to the user, or simply logging it at the right level.
This is why the try: block should never contain more than one single line, with the except block(s) limited only to the errors that can be expected from that line and that you explicitly want to handle at that point. Trying multiple lines and handling generic levels is a perfect way to get errors that are difficult to track.