The performance cost of creating and throwing an Exception
in Java can, and normally always is significantly more taxing than pre-validating a value can be converted. For all JVM's I am aware of (IBM's Java, Oracle's Java, OpenJDK, etc.) the cost of the exception also often linearly scales relative to the depth of the call stack when the exception is thrown, so deeply-nested exceptions are more costly than exceptions in the main-method....
The bottom line is that in good code you should never (with very few exceptions) make exceptions part of the normal/expected flow of the code.
So, in your case, I would minimalize the possibility of exceptions by trying as hard as reasonable to eliminate exception cases, while still handling the exceptions appropriately.
Note that the documentation for Double.valueOf(String) alludes to this and also provides a regular expression useful for checking whether valueOf may throw an exception.
private static final Pattern isInteger = Pattern.compile("[+-]?\\d+");
public static final int tryParseInt(String value) {
if (value == null || !isInteger.matcher(value).matches()) {
return 0;
}
try {
return Integer.parseInt(value);
} catch(NumberFormatException nfe) {
return 0;
}
}
While the additional checks may slow down valid numbers slightly, it drastically improves the performance of handling invalid numbers in the majority of the cases, and the trade-off is, in my experience more than worth it.