Java Exception Handling Question and Answers

5. What are the different ways to handle exceptions?
  There are two ways to handle exceptions.
  • By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and
  • List the desired exceptions in the throws clause of the method and let the caller of the method handle those exceptions.
 
Your Name Your Email-ID
Your Answer
6. Explain the user defined exceptions?
 
  • User defined exceptions are custom exception classes defined by the user for specific purpose.
  • A user defined exception can be created by simply sub classes an exception class or a sub class of an exception class.
  • This allows custom exceptions to be generated (using throw clause) and caught in the same way as normal exception.
 
Your Name Your Email-ID
Your Answer
7. What is exception in java?
 
  • Exception is an error event that can happen during the execution of a program and disrupts its normal flow.
  • Exception can arise from different kind of situations such as wrong data entered by user, hardware failure, network connection failure etc.
  • Whenever any error occurs while executing a java statement an exception object is created and then JRE tries to find exception object is passed to the handler code to process the exception, known as catching the exception.
  • If no handler is found then application throws the exception to runtime environment and JRE terminates the program.
  • Java Exception handling framework is used to handle runtime errors only, compile time errors are not handled by exception handling framework.
 
Your Name Your Email-ID
Your Answer
8. What are the different kinds of exceptions?
  There are two types of exceptions.
  • Checked exception
  • Unchecked exception
 
Your Name Your Email-ID
Your Answer
1234 Page 2 of 4