nerdexam
Oracle

1Z0-803 · Question #77

Given: public class Main { public static void main(String[] args) { try { doSomething(); } catch (SpecialException e) { System.out.println(e); }} static void doSomething() { int [] ages = new int[4];

The correct answer is C. Exception in thread "main". The following line causes a runtime exception (as the index is out of bounds): A runtime exception is thrown as an ArrayIndexOutOfBoundsException. Note: The third kind of exception (compared to checked exceptions and errors) is the runtime exception. These are exceptional conditi

Handling Exceptions

Question

Given:

public class Main { public static void main(String[] args) { try { doSomething(); } catch (SpecialException e) { System.out.println(e); }} static void doSomething() { int [] ages = new int[4]; ages[4] = 17; doSomethingElse(); } static void doSomethingElse() { throw new SpecialException("Thrown at end of doSomething() method"); } } What is the output?

Options

  • ASpecialException: Thrown at end of doSomething() method
  • BError in thread "main" java.lang.
  • CException in thread "main"
  • DSpecialException: Thrown at end of doSomething() method at

How the community answered

(29 responses)
  • A
    7% (2)
  • B
    21% (6)
  • C
    62% (18)
  • D
    10% (3)

Explanation

The following line causes a runtime exception (as the index is out of bounds): A runtime exception is thrown as an ArrayIndexOutOfBoundsException. Note: The third kind of exception (compared to checked exceptions and errors) is the runtime exception. These are exceptional conditions that are internal to the application, and that the application usually cannot anticipate or recover from. These usually indicate programming bugs, such as logic errors or improper use of an API. Runtime exceptions are not subject to the Catch or Specify Requirement. Runtime exceptions are those indicated by RuntimeException and its subclasses.

Topics

#exception propagation#ArrayIndexOutOfBoundsException#try-catch#custom exceptions

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice