August 2003
Intermediate to advanced
672 pages
16h 23m
English
Earlier examples in this chapter have shown how an exception is thrown implicitly during execution. A program can explicitly throw an exception using the throw statement. The general format of the throw statement is as follows:
throw <object reference expression>;
The compiler ensures that the <object reference expression> is of type Throwable class or one of its subclasses. At runtime a NullPointerException is thrown if the <object reference expression> is null. This ensure that a Throwable will always be propagated. A detail message is often passed to the constructor when the exception object is created.
throw new ArithmeticException("Integer division by 0");
When an exception is thrown, normal execution is suspended. ...
Read now
Unlock full access