1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN" 3"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd"> 4<section id="safe_numerics.exception_policies.trap_exception"> 5 <title>trap_exception</title> 6 7 <section> 8 <title>Description</title> 9 10 <para>This exception policy will trap at compile time any operation that 11 <emphasis><emphasis role="bold">COULD</emphasis></emphasis> result in a 12 runtime exception. It can be used in an environment which can tolerate 13 neither arithmetic errors nor runtime overhead. Usage of this policy will 14 almost always require altering one's program to avoid exceptions.</para> 15 </section> 16 17 <section> 18 <title>Model of</title> 19 20 <para><link 21 linkend="safe_numerics.promotion_policy">ExceptionPolicy</link></para> 22 </section> 23 24 <section> 25 <title>Header</title> 26 27 <para><code><ulink url="../../include/exception_policy.hpp"><code>#include 28 <boost/safe_numerics/exception_policy.hpp> 29 </code></ulink></code></para> 30 </section> 31 32 <section> 33 <title>Example of use</title> 34 35 <programlisting>#include "../../include/safe_integer.hpp" 36#include "../../include/automatic.hpp" 37#include "../../include/exception_policies.hpp" 38 39int main(){ 40 using namespace boost::numeric; 41 safe<char, automatic, trap_exception> x, y; 42 y = x * x; // compile error here !!! 43 auto z = x * x; // compile OK 44 return 0; 45}</programlisting> 46 </section> 47</section> 48