13
Exception Handlers
•The NumberFormatException class is derived from the IllegalArgumentException class.
–this means that the IllegalArgumentException class is more general than the NumberFormatException
–try
–{
–  number = Integer.parseInt(str);
–}
–catch (IllegalArgumentException e)
–{
–  System.out.println("Bad number format.");
–}
–catch (NumberFormatException e) // this is an ERROR because the more specific exception follows the more general exception.
–{
–  System.out.println(str + " is not a number.");
–}
This will be caught by the compiler because NumberFormatException is derived from IllegalArgumentException (see page 765)
Re-ordering the catch blocks will make the code compile