Default Exception Handling: If any exception has occurred in the method then method creates an Object known as Exception Object and this object will be handled by JVM. When a method creates an Exception object and hand over it to JVM it’s called throwing an Exception. This Exception object holding all the details about exception like name, description of exception and retain the state of the program where an exception occurred. There may be a chance when multiple exceptions occurred in different methods. This ordered list of the methods is called Call Stack.
Now here is the procedure that will happen.
- First, the run-time system finds the method in the call stack that has an Exception handler. By means of Exception handler if any method that contains a block of code that can handle the occurred exception.
- The run-time system starts searching which methods were called. It means the run-time system tries to find the caller.
- If it finds any handler for a thrown exception(a type of the exception object thrown matches the type of the exception which used in handler).
- If run time system(JVM) doesn’t find the appropriate handler then default exception handler will handle the exception, which is part of the run-time system. It prints the exception and terminates the program abnormally.