int fesetexceptflag (const fexcept_t* flagp, int excepts);
Set floating-point exception flags
Attempts to set the exceptions indicated by excepts with the states stored in the object pointed by flagp.

If successful, the function changes the current state of the floating-point environment, setting the requested exception flags, but without actually raising the exceptions.

Programs calling this function shall ensure that pragma FENV_ACCESS is enabled for the call.


Pointer to a fexcept_t object with a representation of floating-point exceptions.
The value pointed by flagp shall have been previously set by a call to fegetexceptflag with at least the exceptions specified by excepts.
Bitmask value: A combination (with bitwise OR) of any number of floating-point exception values supported by the implementation:
macro valuedescription
FE_DIVBYZEROPole error: division by zero, or some other asymptotically infinite result (from finite arguments).
FE_INEXACTInexact: the result is not exact.
FE_INVALIDDomain error: At least one of the arguments is a value for which the function is not defined.
FE_OVERFLOWOverflow range error: The result is too large in magnitude to be represented as a value of the return type.
FE_UNDERFLOWUnderflow range error: The result is too small in magnitude to be represented as a value of the return type.
FE_ALL_EXCEPTAll exceptions (selects all of the exceptions supported by the implementation).
Certain library implementations may support additional floating-point exception values (with their corresponding macros also beginning with FE_).
Libraries may define in <fenv.h> only the macro values above they support (the others may not be defined).
At least all of the above macro values are defined in <cfenv> (even if not supported by the implementation).

Return Value

Zero, if the function successfully set the flags in the (or if excepts was zero).
A non-zero value otherwise.

Data races

Each thread maintains a separate floating-point environment with its own state. Spawning a new thread copies the current state. [This applies to C11 and C++11 implementations]


No-throw guarantee: this function never throws exceptions.
Note that C floating-point exceptions are not C++ exceptions, and thus are not caught by try/catch blocks.
Calling this function with pragma FENV_ACCESS off causes undefined behavior.

See also