Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Exception_handling

Total questions: 15

Worksheet time: 7mins

Name
Class
Date
1.

What is the root class of Java Exception Hierarchy

a)

Throwable

b)

Exception

c)

Error

d)

Bug

2.

What is the advantage of Exception Handling

a)

To avoid abnormal termination of a program

b)

To find out errors

c)

To Debug program

d)

None of these

3.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

4.

try block may or may not contains catch blocks

a)

True

b)

False

5.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

6.

Choose an exception if attempt to divide number by zero


int number = 89 / 0;

System.out.println("The answer is " + number);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundException

7.

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");

a)

finished

b)

runtime error.

c)

Compilation fails

d)

Exception.

8.

class Main {

public static void main(String args[]) {

try {

throw 10;

}

catch(int e) {

System.out.println("Got the Exception " + e);

}

}

}

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

none

9.

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)

A

b)

B

c)

AC

d)

BC

10.

Which exception will throw if it is division by zero?

a)

NumberFormatException

b)

ArithmeticException

c)

NullPointerException

d)

None of these

11.

What happen in case of multiple catch blocks

a)

Either super or subclass can be caught first.

b)

The superclass exception must be caught first.

c)

The superclass exception cannot caught first.

d)

None of these

12.
Which Java exceptions are unchecked?
a)
IOException.
b)
ClassNotFoundException.
c)
RuntimeException.
d)
SQLException.
13.
What is the difference between throw and throws?
a)
Used interchangeably.
b)
"throw" is used to throw exceptions, "throws" is used in method declarations.
c)
"throw" is used in method declarations, "throws" is used to throw exceptions.
d)
Both are used to handle exceptions.
14.
What is the difference between RuntimeException and IOException?
a)
None, they're the same.
b)
IOException is checked, RuntimeException is unchecked.
c)
RuntimeException is checked, IOException is unchecked.
d)
Both are unchecked.
15.

Exception is a class/interface/abstract class/other?

a)

Class

b)

Interface

c)

Abstract class

d)

Other