From cppreference.com
intferaiseexcept(intexcepts);(since C++11)Attempts to raise all floating point exceptions listed in excepts (a bitwise OR of the
floating point exception macros
). If one of the exceptions is
or
, this function may additionally raise
. The order in which the exceptions are raised is unspecified, except that
and
are always raised before
.
Parameters
excepts - bitmask listing the exception flags to raise Return value
0 if all listed exceptions were raised, non-zero value otherwise.
Example
Run this code
#include<cfenv>#include<iostream>// #pragma STDC FENV_ACCESS ONintmain(){std::feclearexcept(FE_ALL_EXCEPT);constintr=std::feraiseexcept(FE_UNDERFLOW|FE_DIVBYZERO);std::cout<<"Raising divbyzero and underflow simultaneously "<<(r?"fails":"succeeds")<<" and results in\n";constinte=std::fetestexcept(FE_ALL_EXCEPT);if(e&FE_DIVBYZERO)std::cout<<"division by zero\n";if(e&FE_INEXACT)std::cout<<"inexact\n";if(e&FE_INVALID)std::cout<<"invalid\n";if(e&FE_UNDERFLOW)std::cout<<"underflow\n";if(e&FE_OVERFLOW)std::cout<<"overflow\n";}Output:
Raising divbyzero and underflow simultaneously succeeds and results in division by zero underflow See also