I have a rather complex project here that involves a lot of calculations. Now I have a case where the result is NaN. Since a lot of classes are involved in the calculations (and NaNs tend to spread like zombies), the origin is difficult to make out.
Now I’m wondering, does anyone know of a way to make the eclipse debugger stop execution hits a NaN? Since Java doesn’t support automatically raising an exception on NaN, that would be difficult, but perhaps it has be done, and I am missing it?
Thanks,
Axel
PS: I know I could add conditional breakpoints (or if-statements) on Double.isNaN(value), but I would have to do so in a lot of places. (In fact that is what I am about to do right now.) Just wondering if there’s a better alternative.
I doubt it.
Since the normal Java behavior is to not throw exceptions when NaNs appear, the debugger would need to insert conditional breakpoints at each statement that might generate one. That’s going to be complicated to implement and expensive at runtime. And your use-case is pretty unusual one.
I think a better approach might be to add Java assertions to your code at a few well-chosen places.