Sun Studio 12 Update 1: C++ User's Guide

15.4 Error Handling

The complex library has these definitions for error handling:


extern int errno;
class c_exception {...};
int complex_error(c_exception&);

The external variable errno is the global error state from the C library. errno can take on the values listed in the standard header errno.h (see the man page perror(3)). No function sets errno to zero, but many functions set it to other values.

To determine whether a particular operation fails:

  1. Set errno to zero before the operation.

  2. Test the operation.

The function complex_error takes a reference to type c_exception and is called by the following complex arithmetic library functions:

The default version of complex_error returns zero. This return of zero means that the default error handling takes place. You can provide your own replacement function complex_error that performs other error handling. Error handling is described in the man page cplxerr(3CC4).

Default error handling is described in the man pages cplxtrig(3CC4) and cplxexp(3CC4) It is also summarized in the following table.

Complex Arithmetic Library Function  

Default Error Handling Summary  

exp

If overflow occurs, sets errno to ERANGE and returns a huge complex number.

log, log10

If the argument is zero, sets errno to EDOM and returns a huge complex number.

sinh, cosh

If the imaginary part of the argument causes overflow, returns a complex zero. If the real part causes overflow, returns a huge complex number. In either case, sets errno to ERANGE.