The following code fragment shows how to declare that a method throws an exception, and then to actually throw one:
public ComplexFloat divideBy( ComplexFloat divisor )
throws DivideByZeroException;
{
...
throw new DivideByZeroException( );
...
}
Remember that an exception, like everything else in Java, is an object -
thus we have to use 'new' to create one.