Here’s a silly gotcha in the Java language. I’ve got a method that parses a String to an int and returns a default value if the String cannot be parsed:
int parseOrDefault(String val, int def) {
try {
return Integer.parseInt(val);
} catch (NumberFormatException e) {
return def;
}
}