nerdexam
Oracle

1Z0-803 · Question #63

Given: Which approach ensures that the class can be compiled and run?

The correct answer is A. Put the throw new Exception() statement in the try block of try ?catch. We need to catch the exception in the doSomethingElse() method. private static void doSomeThingElse() { throw new Exception();} catch (Exception e) Note: One alternative, but not an option here, is the declare the exception in doSomeThingElse and catch it in the doSomeThing metho

Handling Exceptions

Question

Given:

Which approach ensures that the class can be compiled and run?

Exhibit

1Z0-803 question #63 exhibit

Options

  • APut the throw new Exception() statement in the try block of try ?catch
  • BPut the doSomethingElse() method in the try block of a try ?catch
  • CPut the doSomething() method in the try block of a try ?catch
  • DPut the doSomething() method and the doSomethingElse() method in the try block of a try ?catch

How the community answered

(44 responses)
  • A
    82% (36)
  • B
    2% (1)
  • C
    7% (3)
  • D
    9% (4)

Explanation

We need to catch the exception in the doSomethingElse() method. private static void doSomeThingElse() { throw new Exception();} catch (Exception e) Note: One alternative, but not an option here, is the declare the exception in doSomeThingElse and catch it in the doSomeThing method.

Topics

#try-catch#checked exceptions#compilation error

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice