Hi,
Is it a good way to try something useless just to see if a particular exception is thrown by this code ?
I want to do something when the exception is thrown, and nothing otherwise.
try {
new BigDecimal("some string"); // This do nothing because the instance is ignored
} catch (NumberFormatException e) {
return false; // OK, the string wasn't a well-formed decimal
}
return true;
There is too many preconditions to test, and the constructor BigDecimal() is always checking them all, so this seem the simplest method.