Question: To keep from losing debugging information when you throw a custom exception, you should use a feature called ____________________. 1 points Question 2 Java locates

  1. To keep from losing debugging information when you throw a custom exception, you should use a feature called ____________________.

1 points

Question 2

  1. Java locates the code that handles an exception by searching through the ________________.

1 points

Question 3

  1. All exception classes are derived from the ____________ class.

1 points

Question 4

  1. Code thats executed in response to an exception is called a/an ____________________.

1 points

Question 5

  1. Exceptions that you must handle explicitly in your applications are called ____________ exceptions.

1 points

Question 6

  1. Code example 16-1 Scanner sc = new Scanner(System.in); System.out.print("Enter a number less than 10: "); boolean tryAgain = true; while (tryAgain) { try { int num = sc.nextInt(); if (num >= 10) { throw new InputMismatchException(); } tryAgain = false; } catch(InputMismatchException ime) { System.out.print("Enter a valid integer: "); } sc.nextLine(); }

    (Refer to code example 16-1.) What happens if the user enters 11 at the prompt?

    a.

    No exceptions are thrown and tryAgain is set to false.

    b.

    A runtime error occurs.

    c.

    An InputMismatchException is thrown and tryAgain remains set to true.

    d.

    An InputMismatchException is thrown and tryAgain is set to false.

1 points

Question 7

  1. To make the code that follows compile, what should the declaration of the getStudent() method be? public void getStudent() { readGrades(); } public void readGrades() throws IOException { boolean gradesAvailable = true; if (!gradesAvailable) { throw new IOException(); } }

    a.

    public void getStudent() throw new IOException(){...}

    b.

    public void getStudent(){...}

    c.

    public static void getStudent(){...}

    d.

    public void getStudent() throws IOException{...}

1 points

Question 8

  1. In which of the following situations should you define a custom exception class?

    a.

    When you want to change the message for an exception

    b.

    When none of the Java exceptions are appropriate

    c.

    When using a Java exception would expose too many details of a methods operation.

    d.

    All of the above

    e.

    b and c only

1 points

Question 9

  1. What is printed to the console if a FileNotFoundException occurs in the code that follows? try { file = new BufferedReader(new FileReader(fileName)) validName = true; } catch(FileNotFoundException e) { System.err.println("FileNotFoundException"); } catch(IOException e) { System.out.println("IOException"); } finally { System.out.println("Finally"); }

    a.

    Finally

    b.

    FileNotFoundException

    c.

    FileNotFoundException and Finally

    d.

    FileNotFoundException and IOException

1 points

Question 10

  1. In which of the following situations would you typically not throw an exception from a method?

    a.

    When invalid arguments are passed to the method

    b.

    When you need to perform some processing before the exception is handled by the calling method

    c.

    When the exception is handled by the method

    d.

    When you want to test an exception handler

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!