Hi all,
In the code I'm working on to learn Java, I wanted to check to see if a string
can be converted to a BigDecimal, and get the BigDecimal value if so. There is
no assumption that the string is probably a valid BigDecimal, just that it might
be, and I want to get the converted value if so.
In my code, I used a Try with an empty Catch so that the string conversion would
either succeed or fail which would both test and do the conversion in 1 step.
This seems to break 2 commonly quoted best practices, though. One is to never
use an empty Catch, and the other is to never use exception handling for
something other than exception handling. The alternatives, though, seem to
involve me writing my own code to check the validity of the string as a
BigDecimal which would be duplicating logic that is already in the standard
classes (the code that validates and raises the exception) and increases the
likelihood of bugs.
Opinions?
Thanks,
- Steve Jorgensen