Answer the question
In order to leave comments, you need to log in
Proper exception handling?
Hello. There is a wrapper class above the class. In my wrapper, I provide for several cases where things can go wrong - invalid data was passed, the original class returned incorrect data, and so on. Each such case throws a different exception.
The question is how to catch them correctly when using a class? Catch the basic exception, or catch each specific one with a ladder?
Answer the question
In order to leave comments, you need to log in
Ladder to catch from more specific to more general. The most general is intercepted last.
The question is how to catch them correctly when using a class? Catch the basic exception, or catch each specific one with a ladder?
Depends on the exception handling logic. If you want to choke them just so that they don’t fly out to the client, but log them in catch, then catching a general exception will do. If you have the opposite - the most diverse set of handlers for such situations - then the approach is "from the particular to the general from top to bottom."
Now they will throw stones at me... But exceptions are evil!
They consume a lot of time and resources, often nothing can be fixed, the execution context is torn, etc.
So,
1) Do checks, use defaults wherever possible.
2) If an exception has already occurred, then process it immediately, at the same level.
3) Don't get carried away creating your own exceptions! In 95% of cases, the situation can be eliminated without them! And in the remaining 5%, standard system ones are enough.
4) All uninterruptible exceptions - handle at the upper levels Here
is what I wanted to say - java-performance.info/throwing-an-exception-in-jav...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question