Explain Default exception handling in Java?

Default exception handling in Java ?

Explain Default exception handling in Java?

Explain Default exception handling in Java?
  • Inside a method, if any exception occurs the method in which it is raised is responsible to create exception object by including the following information.
    1. Name of exception
    2. Description of exception
    3. Location at which exception occurs(Stack trace).
  • After creating exception object method handover that objects to the JVM.
  • JVM will check whether the method contains any exception handling code or not.
  • If the method doesn’t contain exception handling code than JVM terminates abnormally and removes corresponding entry from the stack.
  • Then JVM identifies caller method and checks whether caller method contains any handling code or not.
  • If the caller method doesn’t contain handling code then JVM terminates the caller method also abnormally and removes corresponding entry from the stack.
  • This process will be continued until mail main method and if the main method also doesn’t contain handling code then JVM terminate the main method abnormally and removes corresponding entry from the stack.
  • Then JVM handovers responsibility of exception handling to default exception handler, which the part of JVM.
  • Default exception handler print exception info in the following format and terminate program abnormally.

Note:- In a program, at least one method terminates abnormally then the program termination is abnormal termination. If all method terminated normally then only program termination is normal termination. 

Benefits of handling the exceptions
  • Separation of the error logic or exception logic from our regular business logic.
  • Grouping and differentiating the exception types.
  • Handling the exception and making the program to terminate normally or successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

%d bloggers like this: