Signup/Sign In

Exception Handling

This Test will cover Exception Handling from basic to advanced level. All that you studied in the Notes.
Q. What is the base class for all Exception ?
Q. Which type of exception will be thrown when you run this code ?

int a = 100, b = 0;
int c = a/b;

Q. What will happen when an exception occur inside your code?
Q. What should replace XXXX ?

class MyException extends Exception 
{
  public void method() throws XXXX
  {
    throw new MyException(); 
  }
}
Q. What will happen on running the following code ?

try
{
  int arr[]={1,2};
  arr[2]=3/0;
  System.out.println(a[0]);         
}
catch(Exception e)
{
  System.out.println("Exception");
}
catch(ArithmeticException e)
{
  System.out.println("Divide by Zero");
}
Q. What will be the Output of the given code ?

public class test 
{
  static void method(){} 
  public static void main(String []args) throws Exception
  {
   try
   {
      method();
      System.out.println("try");
   }
   catch(Exception e)
   {
      System.out.println("catch");
   }
   finally
   {
      System.out.println("finally");
   }     
  }
}
Q. JDK 7 introduced a new version of try statement known as ?

Q. What will be the Output of the given program?

import java.io.*;
class Super
{
 void show() 
 { System.out.println("parent"); }
}

public class Sub extends Super 
{
  void show() throws IOException		
  { System.out.println("child"); } 

  public static void main( String[] args )
  {
    Super s = new Sub();
    s.show();
  }  
}
Q. Complete the following statement ?
If Super class method throws an exception, then Subclass overriden method .......
Q. In chained exception which method relates one exception with another exception ?
Q. getCause() method of Throwable is used to ?

Related Tests: