Search your topic in Java2share
Home > FAQs
eXTReMe Tracker


Exception Handling FAQs


Untitled Document

Q1.What is an Exception?
Ans.An unwanted, unexpected event that disturbs normal flow of the program is called Exception.Example: FileNotFondException.

Q2.What is the purpose of Exception Handling?
Ans.The main purpose of Exception Handling is for graceful termination of the program.

Q3.What is the meaning of Exception Handling?
Ans. Exception Handling doesn’t mean repairing an Exception, we have to define alternative way to continue rest of the code normally.
Example: If our programming requirement is to read the data from the file locating at London but at Runtime if London file is not available then we have to use local file alternatively to continue rest of program normally. This is nothing but Exception Handling.


Q4.Explain Default Exception Handling Mechanism in java?
Ans.If an exception raised, the method in which it’s raised is responsible for the creation of  Exceptions object by including the following information:

  • Name of the Exception
  • Description of the Exception
  • Stack Trace
  • After creating Exception object the method handover it to the JVM.
  • JVM checks for Exception Handling code in that method.
  • If the method doesn’t contain any Exception handling code then JVM terminates the method abnormally and removes the corresponding entry from the stack.
  • JVM identify the caller method and checks for Exception Handling code in that method. If the caller doesn’t contain any exception handling code then JVM terminates that method abnormally and removes the corresponding entry from the stack.
  • This process will be continue until main() method.
  • If the main() method also doesn’t contain exception handling code the JVM terminates that main() method and removes the corresponding entry from the stack.
  • Just before terminating the program abnormally JVM handovers the responsibility of exception handling to the Default Exception Handler which is the component of JVM.
  • Default Exception Handler just print exception information to the consol in the following format

Name of Exception: Description
Stack Trace (Location of the Exception)