N
N
Nikita2018-04-16 12:42:54
Java
Nikita, 2018-04-16 12:42:54

Why is it necessary to rethrow exceptions?

Do I understand correctly that repeated exceptions take us to a higher level? But to a higher level of what if it still remains at the Exception level?

catch(Exception e){
System.err.println("Было возбуждено исключение");
throw e; 
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-04-16
@NeToster

Rethrowing an exception allows your code to react to the exception, not to swallow it, but to forward it to the calling code so that it can also react to it somehow.

E
Eugene, 2018-04-16
@klim76

to a higher level,

call tree. Just do not forget in the method where you have this written
catch(Exception e){
System.err.println("An exception was thrown");
throw e;
}

append throws [your exception class]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question