Why Throwable is dangerous in catch() block ?
When you say :-
try
{
.............
..............
.............
}
catch(Throwable throwable)
{
..........
}
In the above case catch can handle all kinds of Exceptions even the "Error" and its subclass.
Lets take an Example of OutOfMemoryError(OOME), when statements in try block raises an Error "OOME", JVM is able to find the handler for this so, in this case the thread which generated this error will not die. whereas in case of handling or putting Exception in catch block instead of Throwable, JVM finds the handler and the thread(which raises the Exception) continues to run thereby not halting the program but if the Handler/Catch block for that particular Exception is not provided then Thread dies. so what if you are handling or providing catch block for the Error and its Subclass and not Exception and its subclass, then the Thread which raises the Error continues to live. I this case, the JVM continued running, crippled and limping, instead of turning to an honorable solution like killing it. Choosing the quick death route would have been rewarded with a quick resurrection to be provided by the gracious NodeAgent and its watchdog mechanism, and the end result would have been a newly born healthy server ready to get back in business. A retreat in order to attack, you might put it. Instead, the server had to limp for long minutes, suffering from a series of consecutive strokes (OOME), until the OOME was so bad that the JVM just had to exit.
try
{
.............
..............
.............
}
catch(Throwable throwable)
{
..........
}
In the above case catch can handle all kinds of Exceptions even the "Error" and its subclass.
Lets take an Example of OutOfMemoryError(OOME), when statements in try block raises an Error "OOME", JVM is able to find the handler for this so, in this case the thread which generated this error will not die. whereas in case of handling or putting Exception in catch block instead of Throwable, JVM finds the handler and the thread(which raises the Exception) continues to run thereby not halting the program but if the Handler/Catch block for that particular Exception is not provided then Thread dies. so what if you are handling or providing catch block for the Error and its Subclass and not Exception and its subclass, then the Thread which raises the Error continues to live. I this case, the JVM continued running, crippled and limping, instead of turning to an honorable solution like killing it. Choosing the quick death route would have been rewarded with a quick resurrection to be provided by the gracious NodeAgent and its watchdog mechanism, and the end result would have been a newly born healthy server ready to get back in business. A retreat in order to attack, you might put it. Instead, the server had to limp for long minutes, suffering from a series of consecutive strokes (OOME), until the OOME was so bad that the JVM just had to exit.
Comments
Post a Comment