Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if you throw an Exception from inside UncaughtExceptionHandler?

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?

like image 250
Umut Utkan Avatar asked Jan 10 '11 22:01

Umut Utkan


People also ask

Is it possible to throw an inbuilt exception?

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.

What happens if an exception is thrown during the handling of an exception?

If the exception-handling implementation catches you doing either, it will terminate your program.

Does throwing an exception stop execution?

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.

Can we throw exception from controller?

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.


1 Answers

Quote from the method's Javadoc:

Any exception thrown by this method will be ignored by the Java Virtual Machine.

like image 119
Péter Török Avatar answered Sep 28 '22 17:09

Péter Török