WorksheetsException_handling
Total questions: 15
Worksheet time: 7mins
What is the root class of Java Exception Hierarchy
Throwable
Exception
Error
Bug
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
try block may or may not contains catch blocks
True
False
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
finished
runtime error.
Compilation fails
Exception.
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
Got the Exception 10
Got the Exception 0
Compiler Error
none
class exception_handling
{ public static void main(String args[])
{ try
{ int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
} catch(ArithmeticException e)
{ System.out.print("B");
}
finally
{ System.out.print("C");
}
}
}
A
B
AC
BC
Which exception will throw if it is division by zero?
NumberFormatException
ArithmeticException
NullPointerException
None of these
What happen in case of multiple catch blocks
Either super or subclass can be caught first.
The superclass exception must be caught first.
The superclass exception cannot caught first.
None of these
Exception is a class/interface/abstract class/other?
Class
Interface
Abstract class
Other
