Will also help with graphics programs etc too! Often get crashes in matplotlib from this...
This is indeed another very good point. We’ve had issues with wxPython as well and I remember having to sandwich some call calling into wxPython with an enabling/disabling of traps. Note that I did write a long time ago a nice utility which can be used both in C++ and Python:
In Python, it uses a context:
>>> import boost.python
>>> from scitbx.array_family import flex
>>> a = flex.double((0, 0, 0))
>>> with boost.python.trapping(division_by_zero=False):
>>> b = 1/a
>>> tuple(b)
(inf, inf, inf)
>>> 1/a
... CRASH ...
In C++, it uses the guard pattern:
#include <boost_adaptbx/floating_point_exception.h>
{
exception_trapping guard(exception_trapping::division_by_zero | exception_trapping::invalid);
// the computations in this scope will now trap division-by-zero and NaN
// when leaving the scope, trapping will go back to what it was before entering the scope
}