Rethrow
Whenever you want to notify the caller's method of an exception, you get a catch and rethrow exception.
Let's say some callSomething () method calls your something () method. If any exception occurs inside something (), it will simply catch the exception, so the application does not interrupt and reinstalls it on the callSomething () method. Then callSomething () will notify the client of an internal error.
Another example is that in the MVC template, the request sent by the client is served by some method from the controller based on query matching. The controller will call the service and the service will interact with some dao method. If some kind of exception occurs in the DAO, then the DAO cancels the exception for the service, the service will be redirected to the controller, and this is the controller that will notify the client of the error. This is known as throwing exceptions in java. An exception extends from method to method, to the call stack, until it is caught.
Multi catch
If you want to perform the same action for several types of exceptions, then you use multiple catch.
source share