Java Programming — Exception Handling
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 51–60 of 100 questions in Exception Handling
Q.51 Medium Exception Handling
Which method is used to get the exception that caused the current exception in Java?
A getException()
B getCause()
C getRootCause()
D getOriginalException()
Correct Answer:  B. getCause()
EXPLANATION

The getCause() method returns the Throwable that caused the current exception, enabling exception chaining analysis and debugging.

Take Test
Q.52 Medium Exception Handling
What is the output of exception chaining in Java?
A Multiple exceptions are processed simultaneously
B One exception wraps another exception preserving the original cause
C All exceptions are converted to RuntimeException
D The first exception is ignored
Correct Answer:  B. One exception wraps another exception preserving the original cause
EXPLANATION

Exception chaining wraps a caught exception within another exception using initCause() or constructor, preserving the original exception for debugging and stack trace analysis.

Take Test
Which of the following cannot throw a checked exception without being declared in throws clause?
A Constructor
B Instance initializer block
C Static initializer block
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

Checked exceptions in constructors, instance initializers, and static initializers must be handled with try-catch or declared in throws (constructors only). This is enforced by Java compiler.

Take Test
Q.54 Medium Exception Handling
What will be printed?
public class Test {
public static void main(String[] args) {
try {
System.out.println("In try");
return;
} catch (Exception e) {
System.out.println("In catch");
} finally {
System.out.println("In finally");
}
}
}
A In try\nIn catch\nIn finally
B In try\nIn finally
C In try only
D Compilation error
Correct Answer:  B. In try\nIn finally
EXPLANATION

Try block executes printing 'In try', then return is encountered. Finally block still executes printing 'In finally' before method returns. Catch is skipped as no exception occurs.

Take Test
Which of the following is NOT a characteristic of Exception class in Java?
A It extends Throwable
B It is always checked exception
C Its subclasses may be checked or unchecked
D It can be instantiated directly
Correct Answer:  B. It is always checked exception
EXPLANATION

Exception class has both checked subclasses (like IOException) and unchecked subclasses (like RuntimeException). Not all exceptions extending Exception are checked.

Take Test
Q.56 Medium Exception Handling
What happens if you use 'return' statement inside a finally block?
A The return statement is ignored
B The return statement in finally overrides any return in try/catch
C A compilation error occurs
D The finally block is skipped
Correct Answer:  B. The return statement in finally overrides any return in try/catch
EXPLANATION

A return statement in finally will override and suppress any return value or exception from try/catch blocks. This is considered a bad practice.

Take Test
Which exception is thrown when a method argument is null but shouldn't be?
A NullArgumentException
B NullPointerException
C InvalidArgumentException
D ArgumentNullException
Correct Answer:  B. NullPointerException
EXPLANATION

NullPointerException is thrown when attempting to use an object reference that hasn't been instantiated. Java doesn't have NullArgumentException.

Take Test
Q.58 Medium Exception Handling
What is the output of this code?
public class ExceptionDemo {
public static void main(String[] args) {
try {
int arr[] = new int[2];
arr[5] = 10;
} catch (Exception e) {
System.out.println("Exception caught");
} finally {
System.out.println("Finally block");
}
}
}
A Exception caught
B Exception caught\nFinally block
C Finally block
D No output
Correct Answer:  B. Exception caught\nFinally block
EXPLANATION

ArrayIndexOutOfBoundsException is caught by Exception catch block, printing 'Exception caught'. Finally block always executes regardless, printing 'Finally block'.

Take Test
Q.59 Medium Exception Handling
Consider this code snippet. What will happen?
try {
int x = 5/0;
} catch (NullPointerException e) {
System.out.println("Caught NPE");
}
A Prints 'Caught NPE'
B ArithmeticException will be thrown and not caught
C Program will terminate silently
D A compilation error will occur
Correct Answer:  B. ArithmeticException will be thrown and not caught
EXPLANATION

5/0 throws ArithmeticException, not NullPointerException. The catch block only handles NPE, so ArithmeticException propagates to the caller.

Take Test
What is the difference between 'throw' and 'throws' keywords in Java?
A throw is used to declare exceptions, throws is used to throw them
B throw creates an exception object and throws it, throws declares that a method may throw exceptions
C They are synonyms and can be used interchangeably
D throws is used only with try-catch blocks
Correct Answer:  B. throw creates an exception object and throws it, throws declares that a method may throw exceptions
EXPLANATION

throw explicitly throws an exception object; throws declares in method signature that exceptions may be thrown. Example: throw new IOException() vs public void method() throws IOException.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips