trap_exception.xml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. <section>
  7. <title>Description</title>
  8. <para>This exception policy will trap at compile time any operation that
  9. <emphasis><emphasis role="bold">COULD</emphasis></emphasis> result in a
  10. runtime exception. It can be used in an environment which can tolerate
  11. neither arithmetic errors nor runtime overhead. Usage of this policy will
  12. almost always require altering one's program to avoid exceptions.</para>
  13. </section>
  14. <section>
  15. <title>Model of</title>
  16. <para><link
  17. linkend="safe_numerics.promotion_policy">ExceptionPolicy</link></para>
  18. </section>
  19. <section>
  20. <title>Header</title>
  21. <para><code><ulink url="../../include/exception_policy.hpp"><code>#include
  22. &lt;boost/safe_numerics/exception_policy.hpp&gt;
  23. </code></ulink></code></para>
  24. </section>
  25. <section>
  26. <title>Example of use</title>
  27. <programlisting>#include "../../include/safe_integer.hpp"
  28. #include "../../include/automatic.hpp"
  29. #include "../../include/exception_policies.hpp"
  30. int main(){
  31. using namespace boost::numeric;
  32. safe&lt;char, automatic, trap_exception&gt; x, y;
  33. y = x * x; // compile error here !!!
  34. auto z = x * x; // compile OK
  35. return 0;
  36. }</programlisting>
  37. </section>
  38. </section>