Skip to content
QuiznExam

Exceptions in Java Quiz – 15 Questions with Answers

Test your knowledge of exception handling in Java with 15 questions covering exceptions, try-catch, finally, throw, throws, checked exceptions, unchecked exceptions, and custom exceptions.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What is an exception in Java?

    • A. A syntax rule
    • B. An event that disrupts the normal flow of program execution
    • C. A type of variable
    • D. A Java package
    Show answer

    B. An event that disrupts the normal flow of program execution

    An exception is an event that occurs during program execution and disrupts the normal flow of instructions.

  2. 2. Which keywords are commonly used for exception handling in Java?

    • A. try, catch, finally, throw, throws
    • B. check, error, handle, catch
    • C. try, error, handle, final
    • D. exception, handle, catch, error
    Show answer

    A. try, catch, finally, throw, throws

    Java provides try, catch, finally, throw, and throws as the main keywords for exception handling.

  3. 3. Which block contains code that may throw an exception?

    • A. catch
    • B. finally
    • C. try
    • D. throw
    Show answer

    C. try

    Code that may cause an exception is placed inside a try block so that it can be handled by an appropriate catch block.

  4. 4. Which block is used to handle an exception in Java?

    • A. try
    • B. catch
    • C. finally
    • D. throws
    Show answer

    B. catch

    A catch block contains code that handles an exception thrown from the associated try block.

  5. 5. What is the purpose of the finally block?

    • A. To define a new exception
    • B. To execute cleanup code after try/catch processing
    • C. To prevent all exceptions
    • D. To declare checked exceptions
    Show answer

    B. To execute cleanup code after try/catch processing

    The finally block is generally used for cleanup actions and normally executes after the try/catch processing, including when control leaves those blocks.

  6. 6. Which keyword is used to explicitly throw an exception in Java?

    • A. throws
    • B. throw
    • C. raise
    • D. exception
    Show answer

    B. throw

    The throw keyword is used to explicitly throw a particular exception object.

  7. 7. What is the purpose of the throws keyword?

    • A. To catch an exception
    • B. To declare exceptions that a method may pass to its caller
    • C. To create an exception object
    • D. To terminate the JVM
    Show answer

    B. To declare exceptions that a method may pass to its caller

    The throws clause in a method declaration indicates checked exceptions that the method may propagate to its caller.

  8. 8. Which of the following is a checked exception in Java?

    • A. NullPointerException
    • B. ArithmeticException
    • C. IOException
    • D. ArrayIndexOutOfBoundsException
    Show answer

    C. IOException

    IOException is a checked exception, so code generally must catch it or declare it with throws.

  9. 9. Which class is the superclass of both Error and Exception?

    • A. Throwable
    • B. Object
    • C. RuntimeException
    • D. ExceptionHandler
    Show answer

    A. Throwable

    java.lang.Throwable is the superclass of both Exception and Error in Java's throwable hierarchy.

  10. 10. Which of the following is an unchecked exception?

    • A. IOException
    • B. SQLException
    • C. ClassNotFoundException
    • D. NullPointerException
    Show answer

    D. NullPointerException

    NullPointerException extends RuntimeException, making it an unchecked exception.

  11. 11. What happens if an exception is not caught in the current method?

    • A. It is always ignored
    • B. It propagates to the calling method
    • C. The compiler automatically fixes it
    • D. It is converted into a warning
    Show answer

    B. It propagates to the calling method

    If an exception is not handled in the current method, it can propagate up the call stack to the caller.

  12. 12. Can a Java program have multiple catch blocks for a single try block?

    • A. Yes
    • B. No
    • C. Only for RuntimeException
    • D. Only for Error
    Show answer

    A. Yes

    A try block can be followed by multiple catch blocks to handle different exception types.

  13. 13. What type of exception is typically used as the base class for creating a custom checked exception?

    • A. Error
    • B. Exception
    • C. Object
    • D. ThrowableError
    Show answer

    B. Exception

    A custom checked exception can be created by extending Exception directly or another checked exception type.

  14. 14. What is the result of executing the following statement? throw new IllegalArgumentException();

    • A. It creates and throws an IllegalArgumentException
    • B. It catches the exception automatically
    • C. It declares a checked exception
    • D. It permanently stops compilation
    Show answer

    A. It creates and throws an IllegalArgumentException

    The new expression creates an IllegalArgumentException object and throw transfers control by throwing that exception.

  15. 15. What is the main benefit of exception handling in Java?

    • A. It eliminates all programming errors
    • B. It separates exceptional error handling from normal program flow
    • C. It guarantees faster execution
    • D. It prevents methods from returning values
    Show answer

    B. It separates exceptional error handling from normal program flow

    Exception handling provides a structured way to detect and handle exceptional conditions without mixing all error-handling logic into normal program flow.