Sure.
A large application with several possible problem situations might
define several subclasses of Exception
.
Here is an example of an Exception
child that
could have been used with the example program.
Remember that super()
in the constructor
invokes the constructor of the super class, Exception
.
Now a method can throw a TooYoungException
and
a catch{}
block can catch one.
public class TooYoungException extends Exception { TooYoungException ( int age ) { super( "Age is: " + age ); } }
Have you just thrown a BoredSillyException
?