Exception Example Answers
Given the class ExceptionExample, answer the following questions:
- What is the output if the program executes without any exceptions occurring?
Done methodZ
Done methodY
Done
- What is the output if NullPointerException occurs at line D?
Error 3
Done methodY
Done
- What is the output if NumberFormatException occurs at line F?
Error 5
Done methodZ
Done methodY
Done
- What is the output if ArithmeticException occurs at line F?
Done methodZ
Error 2
Done
- What is the output if ArithmeticException occurs at line C?
Error 2
Done
- What is the output if NumberFormatException occurs at line E?
Done
Program crashes, stack trace is printed
- At what line(s) would there have to be an ArrayIndexOutOfBoundsException to cause the message "Error 1" to be printed
(ignore other things that might be printed as well)?
Only at Line C
Additional questions to consider:
- What is the output if ArrayIndexOutOfBoundsException occurs at line A?
- What is the output if NullPointerException occurs at line B?
- What is the output if ArrayIndexOutOfBoundsException occurs at line D?
- What is the output if NullPointerException occurs at line E?
- What is the output if ArrayIndexOutOfBoundsException occurs at line E?
- What is the output if ClassCastException occurs at line F?