Home Segments Top Top Previous Next

619: Mainline

You can create and throw your own exceptions. To create an exception, you extend the Exception class, as illustrated in the following example:

public class StrangeDataException extends Exception { 
} 

Once you have defined an exception class, you can throw instances:

throw (new StrangeDataException()) 

Those instances are caught by corresponding catchers:

catch (StrangeDataException e) { 
 ... 
}