Not that it is a good design or it is something I am planning to do. Just curious, what happens if you throw an Exception
from inside an UncaughtExceptionHandler
? Is it possible to catch it somewhere?
You can throw a user defined exception or, a predefined exception explicitly using the throw keyword. There are two types of exceptions user defined and predefined each exception is represented by a class and which inherits the Throwable class.
If the exception-handling implementation catches you doing either, it will terminate your program.
The throw statement throws a user-defined exception. Execution of the current function will stop (the statements after throw won't be executed), and control will be passed to the first catch block in the call stack. If no catch block exists among caller functions, the program will terminate.
ExceptionHandler is a Spring annotation that provides a mechanism to treat exceptions thrown during execution of handlers (controller operations). This annotation, if used on methods of controller classes, will serve as the entry point for handling exceptions thrown within this controller only.
Quote from the method's Javadoc:
Any exception thrown by this method will be ignored by the Java Virtual Machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With