try
{
}
catch(ExceptionType name)
{
}
One thing that I'm particularly unable to understand is the argument of Catch Block. We write "catch(ExceptionType name)" What exactly is "name" though? If "ExceptionType" is class, shouldn't "name" be reference to an object? Even if it is a reference, since we haven't created any object, what exactly does it contain?
Now I have come up with this theory regarding Exception Handling - please correct me I'm getting it wrong.
CASE 1 - SUPPOSING NO TRY, CATCH BLOCK EXISTS - If an error occurs, the exception handler automatically generates an exception object[based on exception's class] and hands it over to the JVM and then JVM then returns the function or crashing error to be displayed at the run-time
CASE 2 - IF PROGRAMMER HAS WRITTEN A TRY CATCH BLOCK - If an error occurs, the exception handler generates an exception object[based on exception's class] and then instead of going to the JVM, it will first look into the catch block and try to match the reference variable to the exception object. If the match happens, exception handler hands that object to the catch block reference and then programmer can return the function of his or her choice. However, if the match does not happen, exception handler will hand that exception object back to the JVM.
Is this how Exception Handling work?