Java Exception Handling - 1

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Dthakker11
D
Dthakker11
Community Contributor
Quizzes Created: 3 | Total Attempts: 1,709
Questions: 6 | Attempts: 682

SettingsSettingsSettings
Java Exception Handling - 1 - Quiz

.


Questions and Answers
  • 1. 

    What is the base class for Error and Exception in Java?

    • A.

      Throwable

    • B.

      RunTimeExceptions

    • C.

      Throws

    • D.

      Option 4

    Correct Answer
    A. Throwable
    Explanation
    In the hierarchy of Exceptions, it all starts with Object class (which is a superclass of all classes), and the follows Throwable class.

    Rate this question:

  • 2. 

    I will cause a complier error if you did not declare/handle me in your program. I am :

    • A.

      Checked Exception

    • B.

      Unchecked Exception

    • C.

      All Exceptions

    • D.

      Option 4

    Correct Answer
    A. Checked Exception
    Explanation
    Checked Exception - the name itself suggests it is checked by the Java compiler!! You can not move ahead with execution of your program if you have these exceptions in your coding.

    Rate this question:

  • 3. 

    If a statement tries to divide by zero which exception is thrown?

    • A.

      NullPointerException

    • B.

      NumberFormatException

    • C.

      ArithmeticException

    • D.

      DivideByZeroException

    Correct Answer
    C. ArithmeticException
    Explanation
    When a statement tries to divide by zero, the exception thrown is ArithmeticException. This exception occurs when an arithmetic operation in Java has an illegal or undefined result, such as division by zero. In this case, since the statement is attempting to divide by zero, it will throw an ArithmeticException.

    Rate this question:

  • 4. 

    An instance of _________ describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully.

    • A.

      RunTimeException

    • B.

      Exception

    • C.

      Error

    • D.

      NumberFormatException

    Correct Answer
    C. Error
    Explanation
    An instance of "Error" describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully. Errors are typically caused by serious problems that cannot be easily recovered from, such as out of memory errors or stack overflow errors. They are not meant to be caught and handled like exceptions, but rather indicate a severe problem that may require intervention from the developer or system administrator.

    Rate this question:

  • 5. 

    Two classes of exceptions you should ideally deal in your program are:

    • A.

      Checked Exceptions

    • B.

      Runtime Exceptions

    • C.

      Error class

    • D.

      All Exceptions

    Correct Answer(s)
    A. Checked Exceptions
    B. Runtime Exceptions
    Explanation
    In Java, there are two main types of exceptions that should ideally be dealt with in a program: Checked Exceptions and Runtime Exceptions. Checked Exceptions are the exceptions that are checked at compile-time and are required to be handled or declared in the method signature. They are typically used to handle anticipated errors or exceptional conditions that can occur during the execution of a program. Runtime Exceptions, on the other hand, are not checked at compile-time and do not require explicit handling. They are usually caused by programming errors or unexpected conditions that may occur during the runtime of a program. Therefore, it is important to handle both types of exceptions to ensure proper error handling and program stability.

    Rate this question:

  • 6. 

    Which of the following is true regarding try blocks in Java language?

    • A.

      Try blocks must be placed below a catch block

    • B.

      Try blocks must have at least one corresponding catch block

    • C.

      They always use recursion

    • D.

      Try blocks are only used for Exceptions related to file input and output

    Correct Answer
    B. Try blocks must have at least one corresponding catch block
    Explanation
    Try blocks must have at least one corresponding catch block in Java language because try blocks are used to enclose the code that may throw an exception, and the catch block is used to handle the exception that is thrown. Without a catch block, the code would not be able to handle the exception and would result in a compilation error. Therefore, it is necessary to have a catch block for every try block to handle the potential exceptions.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 15, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jan 30, 2018
    Quiz Created by
    Dthakker11
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.