Library Documentation Index

Safe Numerics

PrevUpHomeNext

ExceptionPolicy<EP>

Description
Notation
Valid Expressions
Header
Models

Description

The exception policy specifies what is to occur when a safe operation cannot return a valid arithmetic result. A type is an ExceptionPolicy if it has functions for handling exceptional events that occur in the course of safe numeric operations.

Notation

EP A type that full fills the requirements of an ExceptionPollicy
message A const char * which refers to a text message about the cause of an exception

Valid Expressions

Any operations which result in integers which cannot be represented as some Numeric type will throw an exception.

Expression Return Value
EP::overflow_error(const char * message) void
EP::underflow_error(const char * message) void
EP::range_error(const char * message) void

Header

#include <safe_numerics/include/concepts/exception_policy.hpp>

Models

The library header <safe_numerics/include/exception_policies.hpp> contains a number of pre-made exception policies:

  • boost::numeric::throw_exception

    If an exceptional condition is detected at runtime throw the exception. Safe types use this exception policy as the default if no other one is specified.

  • boost::numeric::ignore_exception

    Emulate the normal C/C++ behavior of permitting overflows, underflows etc.

  • template<void (*F)(const char *), void (*G)(const char *), void (*H)(const char *)>

    boost::numeric::no_exception_support

    If you want to specify specific behavior for particular exception types, use this policy. The most likely situation is where you don't have exception support and you want to trap "exceptions" by calling your own special functions.

  • boost::numeric::trap_exception

    Use this policy to trap at compile time any operation which would otherwise trap at runtime. Hence expressions such as i/j will trap at compile time unless j can be guaranteed to not be zero.


PrevUpHomeNext