previous |
start |
next .... [Slide 27] ....
Exception Handling
- Example: NullPointerException
String name = null;
int n = name.length(); // ERROR
- Cannot apply a method to null
- Virtual machine throws exception
- Unless there is a handler, program exits with stack
trace
Exception in thread "main"
java.lang.NullPointerException
at Greeter.sayHello(Greeter.java:25)
at GreeterTest.main(GreeterTest.java:6)
previous |
start |
next .... [Slide 27] ....