Given that Integer.parseInt()
throws NumberFormatException, and given:
3. public class Main { 4. public static void main(String[] args) { 5. try { //from w w w. j a v a 2s. c om 6. System.out.println(doStuff(args)); 7. } 8. catch (Exception e) { System.out.println("exc"); } 9. doStuff(args); 10. } 11. static int doStuff(String[] args) { 12. return Integer.parseInt(args[0]); 13. } 14.}
And, if the code compiles, given the invocation:
java Main x
What is the result? (Choose all that apply.)
C is correct.
When "x" is the argument, a NumberFormatException is thrown at line 12.
Because this is a runtime exception, it doesn't have to be declared, and it's still propagated up to main()
.
The first time doStuff()
is invoked, the NumberFormatException is handled in main()
; the second time it is not handled.