Rethrowing an Exception Tutorial

There may be occasions where you want to catch an exception, then determine if it can be handled properly and if not, rethrow the exception to be handled further down the call stack.
The example code for this tutorial will create a method that expands the capabilities of the parseInt() method in the Integer class.
Consider the following:
int stringToInt(String s) {
int i = 0;
try {
i = Integer.parseInt(s);
} catch (NumberFormatException e) {
switch (s.toUpperCase()) {
case "ONE":
return 1;
...
}
throw e;
}
return i;
}

This method can take arguments like "1", "one", "One", "oNe", etc. and convert them all to a primitive int value.

Open the command prompt (CMD - see the Getting Started ) and type in the following commands.

Final thoughts

If you have been following my tutorial series, you may have noticed that there are quite a few tutorials on Exception Handling.
Exception handling is an important topic and quite frankly – IMO – it is not given enough attention by many in the Java community.
I plan on making a few more tutorials on exception handling before I move on to another subject.