<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 11 Apr 2016, at 10:11, <a href="mailto:Graeme.Winter@diamond.ac.uk" class="">Graeme.Winter@diamond.ac.uk</a> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: LucidaSans; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Will also help with graphics programs etc too! Often get crashes in matplotlib from this...</span><br style="font-family: LucidaSans; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote></div><br class=""><div class="">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:</div><div class=""><br class=""></div><div class="">In Python, it uses a context:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &gt;&gt;&gt; import boost.python</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &gt;&gt;&gt; from scitbx.array_family import flex</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a = flex.double((0, 0, 0))</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &gt;&gt;&gt; with boost.python.trapping(division_by_zero=False):</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &gt;&gt;&gt; &nbsp; b = 1/a</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &gt;&gt;&gt; tuple(b)</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; (inf, inf, inf)</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 1/a</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; ... CRASH ...</font></div></div><div class=""><br class=""></div><div class="">In C++, it uses the guard pattern:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">#include &lt;boost_adaptbx/floating_point_exception.h&gt;</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">{</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>exception_trapping guard(exception_trapping::division_by_zero | exception_trapping::invalid);</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// the computations in this scope will now trap division-by-zero and NaN</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// when leaving the scope, trapping will go back to what it was before entering the scope</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><br class=""></div></body></html>