3.2.4 Exception flag handling

The feclearexcept(), fetestexcept(), and feraiseexcept() functions let you clear, test and raise exceptions. The fegetexceptflag() and fesetexceptflag() functions let you save and restore information about a given exception.


The ARM® Compiler toolchain does not support floating-point exception trapping for AArch64 targets.


The following functionality requires a floating-point model that supports exceptions. In ARM Compiler 6 this is disabled by default, and can be enabled by the armclang command-line option -ffp-mode=full.

C99 defines these functions as follows:

void feclearexcept(int excepts);

int fetestexcept(int excepts);

void feraiseexcept(int excepts);

The feclearexcept() function clears the sticky flags for the given exceptions. The fetestexcept() function returns the bitwise OR of the sticky flags for the given exceptions, so that if the Overflow flag was set but the Underflow flag was not, then calling fetestexcept(FE_OVERFLOW|FE_UNDERFLOW) would return FE_OVERFLOW.

The feraiseexcept() function raises the given exceptions, in unspecified order. If an exception trap is enabled for an exception raised this way, it is called.

C99 also provides functions to save and restore all information about a given exception. This includes the sticky flag, whether the exception is trapped, and the address of the trap handler, if any. These functions are:

void fegetexceptflag(fexcept_t *flagp, int excepts);

void fesetexceptflag(const fexcept_t *flagp, int excepts);

The fegetexceptflag() function copies all the information relating to the given exceptions into the fexcept_t variable provided. The fesetexceptflag() function copies all the information relating to the given exceptions from the fexcept_t variable into the current floating-point environment.


You can use fesetexceptflag() to set the sticky flag of a trapped exception to 1 without calling the trap handler, whereas feraiseexcept() calls the trap handler for any trapped exception.
Non-ConfidentialPDF file icon PDF versionARM 100073_0608_00_en
Copyright © 2014–2017 ARM Limited or its affiliates. All rights reserved.