Custom exception exits program, while NumberFormatException only shows error
I created an exception called NegativeNumberException as a test from a book I am reading. The code is as follows:
class NegativeNumberException extends Exception {
public NegativeNumberException() {
super();
}
public NegativeNumberException(String msg) {
super(msg);
}
}
My code "trys" a block of code and catches two possible exceptions:
try {
// code of program
} catch (NumberFormatException nfe) {
System.out.println("Error: " + nfe.getMessage());
} catch (NegativeNumberException nne) {
System.out.println("Error: " + nne.getMessage("Error:Arguments
must all be positive values."));
}
I ran the program which takes multiple arguments which are meant to be positive values, and must be numeric. When it encounters an argument with a nonnumeric value, the NumberFormatException is caught and it displays the general error message and continues execution of the program. However, when it encounters my custom exception NegativeNumberException, it displays the error message and exits the program. Why does it exit the program when the NegativeNumberException is executed?
I tried to do some research on my own by looking at the code for NumberFormatException and see if it did anything different, and it obviously traced back to being a subclass of Exception, just like NegativeNumberException. I don't understand why mine exits. If any more code is needed I can post it, but I didn't think it would be necessary considering all of the workings of this should be in the definition of the exception i created, at least i think.
I appreciate any and all help given, thanks!
-Derek Raimann