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:
1 2 3 4 5 6 7 | int parseOrDefault(String val, int def) { try { return Integer.parseInt(val); } catch (NumberFormatException e) { return def; } } |