Ques 1 Exception Handling
Which keyword is used to declare an exception handler in Java?
a) try
b) catch
c) handle
d) throw
Ques 2 Exception Handling
Which keyword is used to explicitly throw an exception in Java?
a) try
b) catch
c) finally
d) throw
Ques 3 Exception Handling
What is the purpose of the "finally" block in Java exception handling?
a) To handle exceptions that occur in the try block.
b) To provide a place for code that always executes, whether an exception is thrown or not.
c) To specify the type of exception to catch.
d) To re-throw an exception that was caught earlier.
Ques 4 Exception Handling
Which exception class is the superclass for all built-in exceptions in Java?
a) Exception
b) Throwable
c) Error
d) RuntimeException
Ques 5 Exception Handling
Which of the following statements is true about checked exceptions in Java?
a) Checked exceptions are subclasses of the RuntimeException class.
b) Checked exceptions are also known as unchecked exceptions.
c) Checked exceptions must be caught or declared using the "throws" keyword.
d) Checked exceptions are automatically caught by the JVM.
Ques 6 Exception Handling
What is the output of the following Java Code?
try { int result = 10 / 0; System.out.println(result); } catch (ArithmeticException e) { System.out.println("Error: " + e.getMessage()); }
Ques 7 Exception Handling
What is the output of the following Java Code?
try { String str = null; System.out.println(str.length()); } catch (NullPointerException e) { System.out.println("NullPointerException: " + e.getMessage()); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); }