An Exceptional Child

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

Sure.

An Exceptional Child

A large application with several possible problem situations might define several subclasses of Exception. The example program can do this:

public class TooYoungException extends Exception
{

  TooYoungException ( int age )
  {
    super( "Age is: " + age  );
  }

}

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.

QUESTION 13:

Have you just thrown a   BoredSillyException ?