Answer the question
In order to leave comments, you need to log in
Java Exceptions. What to do with a large number of exceptions?
Greetings!
Let's say I have an application with console I/O. The user can enter commands, and the program, in case of some incorrect actions of the user, suggests a solution to this problem (checked exceptions).
Let the user interact with the console and call the method:
public String foo() throws BlaBlaException, BlaFooException, FooFooExcpetion, InfinityException { // и так может очень много
//bla bla
throw new BlaBlaExcpetion();
//. . .
// bla bla
throw new InfinityException();
}
Answer the question
In order to leave comments, you need to log in
At different logical levels, it is possible (and necessary) to re-throw more general types of exceptions (with a link to the original inside), if there is no way to process them in place. For example, TooLongNameException
and NegativePriceException
will become higher somewhere ModelValidationException
, i.e. there, it is enough for you to know that the model is a curve, regardless of the reason for this.
Maybe the example is not the most successful, because inheritance would be suitable here. In general, a large list of exceptions is an indirect sign that the method does too much (S - SOLID).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question