How does an exception get "thrown"?
This is a sketch of what the code of the Color constructor looks
like:
public Color ( int r, int g, int b ) {
if ( r < 0 || r > MAXVALUE )
throw new IllegalArgumentException("Color value out of range- Red");
if ( g < 0 || g > MAXVALUE)
throw new IllegalArgumentException("Color value out of range- Green");
if ( b < 0 || b > MAXVALUE)
throw new IllegalArgumentException("Color value out of range- Blue");
this.r = r;
this.g = g;
this.b = b;
}
So the throw keyword is used to accomplish this. The program
should construct a new Exception of the appropriate type and
throw it. If the code is operating inside of a try
statement somewhere, the exception delivered at a matching catch
clause if there is one.