Use the c_exception class to handle errors that are created by functions and operations in the complex class.
The c_exception class is not related to the C++ exception handling mechanism that uses the try, catch, and throw statements.
The c_exception class lets you handle errors that are created by the functions and operations in the complex class. When the Complex Mathematics Library detects an error in a complex operation or function, it invokes complex_error(). This friend function of c_exception has a c_exception object as its argument. When the function is invoked, the c_exception object contains data members that define the function name, arguments, and return value of the function that caused the error, as well as the type of error that has occurred. The data members are:
complex arg1; // First argument of the error-causing function complex arg2; // Second argument of the error-causing function char* name; // Name of the error-causing function complex retval; // Value returned by default definition of complex_error int type; // The type of error that has occurred.
If you do not define your own complex_error function, complex_error sets the complex return value and the errno error number.
You can either use the default version of complex_error() or define your own version of the function. If you define your own complex_error() function, and this function returns a nonzero value, no error message will be generated.
There are some cases where member functions of the Complex Mathematics Library call functions in the math library. These calls can cause underflow and overflow conditions that are handled by the matherr() function that is declared in the math.h header file. For example, the overflow conditions that are caused by the following calls are handled by matherr():
DBL_MAX is the maximum valid double value, and is defined in float.h. INT_MAX is the maximum int value, and is defined in limits.h.
If you do not want the default error-handling defined by matherr(), you should define your own version of matherr().