You can always make a factory class.
class DoubleFactory{ public static double tryParseDouble(final String number){ double result; try { result = Double.parseDouble(number); } catch (NumberFormatException e) { result = 0.0; } return result; } }
But there is a huge problem with this. Your program will continue to flow normally, but some of your model classes will be broken. And after some other operation, this default value will pop up, and the other will be different. And worst of all, you will not see an exception leading to these broken results. At least you can
catch (NumberFormatException e) {
but the result will be the same - operations using the default value of 0.0 (or -1.0 or another), leading to some unrecoverable state.
source share