How an Exception Handled by JVM

Default Exception Handling Java: If any exception has occurred in the method then the method creates an Object known as Exception Object and this object will be handled by JVM. When a method creates an Exception object and hands over it to JVM it’s called throwing an Exception. This Exception object holding all the details about the exception like the name, description of the 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 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 handling in java object thrown matches the type of the exception which used in handler).
  • If the run time system(JVM) doesn’t find the appropriate handler then the default exception handler will handle the exception, which is part of the run-time system. It prints the exception and terminates the program abnormally.

Leave a Comment

Follow us on Instagram & watch the latest videos on YouTube. Click below social icons to visit our Instagram & YouTube profiles.