Back to Arangodb

exception

3rdParty/boost/1.78.0/libs/safe_numerics/doc/html/exception.html

3.12.9.14.3 KB
Original Source

| |

Safe Numerics

|

exception

Description

Here we describe the data types used to refer to exceptional conditions which might occur. Note that when we use the word "exception", we don't mean the C++ term which refers to a data type, but rather the colloquial sense of a anomaly, irregularity, deviation, special case, isolated example, peculiarity, abnormality, oddity; misfit, aberration or out of the ordinary occurrence. This concept of "exception" is more complex that one would think and hence is not manifested by a single simple type. A small number of types work together to implement this concept within the library.

We've leveraged on the std::error_code which is part of the standard library. We don't use all the facilities that it offers so it's not an exact match, but it's useful and works for our purposes.

enum class safe_numerics_error

The following values are those which a numeric result might return. They resemble the standard error codes used by C++ standard exceptions. This resemblance is coincidental and they are wholly unrelated to any codes of similar names. The reason for the resemblance is that the library started it's development using the standard library codes. But as development progressed it became clear that the original codes weren't sufficient so now they stand on their own. Here are a list of error codes. The description of what they mean is

SymbolDescription
successsuccessful operation - no error returned
positive_overflow_errorA positive number is too large to be represented by the data type
negative_overflow_errorThe absolute value of a negative number is too large to be represented by the data type.
domain_errorthe result of an operation is outside the legal range of the result.
range_erroran argument to a function or operator is outside the legal range - e.g. sqrt(-1).
precision_overflow_errorprecision was lost in the course of executing the operation.
underflow_errorA number is too close to zero to be represented by the data type.
uninitialized_valueAccording to the C++ standard, the result may be defined by the application. e.g. 16 >> 10 will result the expected result of 0 on most machines.

The above listed codes can be transformed to a instance of type std::error_code with the function:

std::error\_codemake\_error\_code(safe\_numerics\_errore)

This object can be

enum class safe_numerics_actions

The above error codes are classified into groups according to how such exceptions should be handled. The following table shows the possible actions that an error could be mapped to.

SymbolDescription
no_actionsuccessful operation - no action action required
uninitialized_valuereport attempt to use an uninitialized value - not currently used
arithmetic_errorreport an arithmetic error
implementation_defined_behaviorreport an operation which the C++ standard permits but fails to specify
undefined_behaviorreport an operation whose result is undefined by the C++ standard.

Translation of a safe_numerics_error into the corresponding safe_numerics_action can be accomplished with the following function:

constexprenumsafe\_numerics\_actionsmake\_safe\_numerics\_action(constsafe\_numerics\_error&e);

See Also

Header

#include <boost/safe_numerics/exception.hpp>

| | Copyright © 2012-2018 Robert Ramey

Subject to Boost Software License

|