Testing for exceptions

The exception flags in the current environment are implemented as bits in a hardware register. You can access the flags in the current environment with the member function GetFlags of an active environment. To create an active environment to test the flags instantiate a TFPEnvironmentModifier object. If you pass no argument to the constructor, it won't change the current environment. This example builds a TFPExceptionSet object containing flags to be tested:

      #pragma fenv_access on
      void CheckSeriousFlags() {
          TFPExceptionSet soughtExceptions(kFPOverflow, kFPInvalid);
          TFPEnvironmentModifier environmentSnapshot;
          if (soughtExceptions.Intersects(environmentSnapshot.GetFlags))
              // overflow or invalid have occurred--alert the user
      }

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker