Class 2 |
Intermediate Java 30-IT-397 |
|
Throwing an Exception
-
An Exception is an object, just like any other.
-
When instantiating it, you can either pass in no arguments, or you can
pass in a String message.
-
To throw it, you just have to type throw and then the object itself.
-
Examples:
throw new Exception("Optional Message");
throw new Exception();
Exception e = new Exception()
throw e;
-
Just make sure that all Exceptions you throw are both declared in the method
signature and caught in the calling method.
Example

Created by: Brandan Jones
December 17, 2001