Site icon DataFlair

Quiz on Exception Handling in Java

quiz on exception handling in java

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Exception handling is a critical concept in Java, acting as a safety net for your programs. Imagine building a complex system: without proper safeguards, a single unexpected error could bring the whole thing crashing down.

Exception handling empowers you to anticipate and gracefully manage these unforeseen circumstances during program execution. By effectively handling exceptions, you can prevent your program from abruptly terminating and maintain its overall stability. This ensures a more robust and user-friendly experience.

This quiz is specifically designed to test your understanding of key exception handling principles in Java. By tackling these questions, you’ll gain valuable insights into how to build resilient and reliable Java applications.

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    Which of the following is not a checked exception ?

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    class Exceptions {

    public static void main ( String args [ ] )

    {

    int a = 2, b = 2 , c = 3;

    int d = a-b;

    float e = c/d;

    System.out.println(e);

    }

    }

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    class Arrays {

    public static void main ( String args [ ] )

    {

     int numbers[ ] = { 1 , 2 , 3 };

    system.out.println(numbers[3]);

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    Classes which inherit runtime expressions and are checked only at runtime are known as ?

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

     class Sample {

    public static void main ( String args [ ] )

    {

    try {

    String data = null;

    if(“DataFlair”.isequals(data)) {

    System.out.println(“The String is DataFlair”);

    }

    }

    catch(Null pointer exception exception) {

    }

    finally{

    System.out.println(“Finally block is always executed”);

    }

    }

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    class ExceptionExample {

    public static void main ( String args [ ] ) 

    {

    try {

    Scanner sc = new Scanner(System.in);

    String a = “DataFlair”;

    a = Integer.parseInt(a);

    }

    catch(Number format expression e) {

    System.out.println(e);

    }

    }

    }

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    Which keyword in Exception handling is used to define exceptions and it specifies that there may occur an exception in the method  ?

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

     Class sample {

    public static void main ( String args [ ] )

    {

    String data = null;

    System.out.println(data.length());

    }

    }

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    Which of the following is a sample for File not found exception ?

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    Which exception in Java is thrown when a thread in process is interrupted ?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    class Main {

    public static void main ( String args [ ] )

    {

    try {

    class.exception sample(“Found an exception”);

    }

        finally {

        System.out.println(‘There may not may not be exception “);

        }

        }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    class ExceptionHandling {

    public static void main ( String args [ ] )

    {

    try {

    int values[ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 }’

    System.out.println(values[9]);

    try {

    System.out.println(values[3]/0);

    }

    catch(Arithmetic Exception exception1) {

    System.out.println(“Arithmetic exception”);

    }

    catch(Arrayoutofbound Exception exception2) {

    System.out.println(“Arrayoutof bound Exception”)’

    }

    }

    }

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    Which block of code is executed always whether the exception is handled or not ?

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    class Example {

    public static void main ( String args [ ] )

    {

    try {

    Example obj = new Example();

    obj.callmethod();

    }

    }

    }

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    class Finallyblock {

    public static void main ( String args [ ] )

    {

    try {

    int a = 10 , b = 20 , c = 30;

    System.out.println(c-(a+b);

    }

    catch(Arithmetic Exception e) {

    }

    finally {

    System.out.println(“Exceptions are raised”);

    }

    }

    }

    Correct
    Incorrect

Summary:

This quiz on exception handling in Java challenges you with various multiple-choice questions to assess your grasp of core concepts. By attempting the quiz, you’ve had the opportunity to identify areas of strength and potential weaknesses in your knowledge of exception handling mechanisms like try-catch blocks, throws clauses, and different types of exceptions (checked vs. unchecked).

Remember, exception handling is a crucial skill for any Java developer. If you encounter difficulties with some questions, don’t be discouraged! Utilize the wealth of online resources available, such as tutorials, practice problems, and online communities, to further solidify your understanding and become a more proficient Java programmer.

Exit mobile version