The ‘parseInt’ method of the ‘Integer ‘ class throws a ‘NumberFormatException’ when it is passed a String argument that it cannot convert to an int. Given the String variable s (which has already been assigned a value), write the code needed to convert the value in s assigning the result to the integer variable i If a NumberFormatException is thrown, i should be assigned the value -1.

LANGUAGE: JAVA

CHALLENGE:

The ‘parseInt’ method of the ‘Integer ‘ class throws a ‘NumberFormatException’ when it is passed a String argument that it cannot convert to an int. Given the String variable s (which has already been assigned a value), write the code needed to convert the value in s assigning the result to the integer variable i

If a NumberFormatException is thrown, i should be assigned the value -1.

SOLUTION:

public class PanicException extends Exception {
   public PanicException() {
      super("PANIC!");
   }

   public PanicException(String msg) {
      super("PANIC! "+msg);
   }
}