User Errors
IMSL functions attempt to detect user errors and handle them in a way that provides as much information to the user as possible. To do this, we recognize various levels of severity of errors, and we also consider the extent of the error in the context of the purpose of the function; a trivial error in one situation may be serious in another. Functions attempt to report as many errors as they can reasonably detect. Multiple errors present a difficult problem in error detection because input is interpreted in an uncertain context after the first error is detected.
What Determines Error Severity
In some cases, the user’s input may be mathematically correct, but because of limitations of the computer arithmetic and of the algorithm used, it is not possible to compute an answer accurately. In this case, the assessed degree of accuracy determines the severity of the error. In cases where the function computes several output quantities, if some are not computable but most are, an error condition exists; and its severity depends on an assessment of the overall impact of the error.
Kinds of Errors and Default Actions
Five levels of severity of errors are defined in the IMSL C Math Library. Each level has an associated PRINT attribute and a STOP attribute. These attributes have default settings (YES or NO), but they may also be set by the user. The purpose of having multiple error types is to provide independent control of actions to be taken for errors of different levels of severity. Upon return from an IMSL function, exactly one error state exists. (A code 0 “error” is no error.) Even if more than one informational error occurs, only one message is printed (if the PRINT attribute is YES). Multiple errors for which no corrective action within the calling program is reasonable or necessary result in the printing of multiple messages (if the PRINT attribute for their severity level is YES). Errors of any of the severity levels except IMSL_TERMINAL may be informational errors. The include file, imsl.h, defines IMSL_NOTE, IMSL_ALERT, IMSL_WARNING, IMSL_FATAL, IMSL_TERMINAL, IMSL_WARNING_IMMEDIATE, and IMSL_FATAL_IMMEDIATE as an enumerated data type Imsl_error.
IMSL_NOTE. A note is issued to indicate the possibility of a trivial error or simply to provide information about the computations.
Default attributes: PRINT=NO, STOP=NO.
IMSL_ALERT. An alert indicates that a function value has been set to 0 due to underflow.
Default attributes: PRINT=NO, STOP=NO.
IMSL_WARNING. A warning indicates the existence of a condition that may require corrective action by the user or calling routine. A warning error may be issued because the results are accurate to only a few decimal places, because some of the output may be erroneous, but most of the output is correct, or because some assumptions underlying the analysis technique are violated. Usually no corrective action is necessary, and the condition can be ignored.
Default attributes: PRINT=YES, STOP=NO.
IMSL_FATAL. A fatal error indicates the existence of a condition that may be serious. In most cases, the user or calling routine must take corrective action to recover.
Default attributes: PRINT=YES, STOP=YES.
IMSL_TERMINAL. A terminal error is serious. It usually is the result of an incorrect specification, such as specifying a negative number as the number of equations. These errors may also be caused by various programming errors impossible to diagnose correctly in C. The resulting error message may be perplexing to the user. In such cases, the user is advised to compare carefully the actual arguments passed to the function with the dummy argument descriptions given in the documentation. Special attention should be given to checking argument order and data types.
A terminal error is not an informational error, because corrective action within the program is generally not reasonable. In normal usage, execution is terminated immediately when a terminal error occurs. Messages relating to more than one terminal error are printed if they occur.
Default attributes: PRINT=YES, STOP=YES.
IMSL_WARNING_IMMEDIATE. An immediate warning error is identical to a warning error, except it is printed immediately.
Default attributes: PRINT=YES, STOP=NO.
IMSL_FATAL_IMMEDIATE. An immediate fatal error is identical to a fatal error, except it is printed immediately.
Default attributes: PRINT=YES, STOP=YES.
The user can set PRINT and STOP attributes by calling imsl_error_options as described in Chapter 12, “Utilities”.
Errors in Lower-Level Functions
It is possible that a user’s program may call an IMSL C Math Library function that in turn calls a nested sequence of lower-level functions. If an error occurs at a lower level in such a nest of functions, and if the lower-level function cannot pass the information up to the original user-called function, then a traceback of the functions is produced. The only common situation in which this can occur is when an IMSL C Math Library function calls a user-supplied routine that in turn calls another IMSL C Math Library function.
The user may interact in three ways with the IMSL error-handling system:
1. | Change the default actions. |
2. | Determine the code of an informational error so as to take corrective action. |
3. | Initialize the error handling systems. |
The functions that support these actions are:
• | imsl_error_options |
Sets the actions to be taken when errors occur.
• | imsl_error_type |
Retrieves the Imsl_error enum error type value.
• | imsl_error_code |
Retrieves the integer code for an informational error.
• | imsl_error_message |
Retrieves the error message string.
• | imsl_initialize_error_handler |
Initializes the IMSL C Math Library error handling system for the current thread. This function is not required but is always allowed. Use of this function is advised if the possibility of low heap memory exists when calling the IMSL C Math Library for the first time in the current thread.
These functions are documented in Chapter 15, Utilities.
Threads and Error Handling
If multiple threads are used then default settings are valid for each thread but can be altered for each individual thread. When using threads it is necessary to set options using imsl_error_options for each thread by calling imsl_error_options from within each thread.
See Example 3 and Example 4 of imsl_error_options for multithreaded examples.
Use of Informational Error to Determine Program Action
In the program segment below, the Cholesky factorization of a matrix is to be performed. If it is determined that the matrix is not nonnegative definite (and often this is not immediately obvious), the program is to take a different branch.
x = imsl_f_lin_sol_nonnegdef (n, a, b, 0);
if (imsl_error_code() == IMSL_NOT_NONNEG_DEFINITE) {
/* Handle matrix that is not nonnegative
definite */
}
Additional Examples
See functions imsl_error_options and imsl_error_code in Chapter 12, Utilities for additional examples.