IMSL C Math Library
error_options
Sets various error handling options.
Synopsis with Optional Arguments
#include <imsl.h>
void imsl_error_options (
IMSL_SET_PRINT, Imsl_error type, int setting,
IMSL_SET_STOP, Imsl_error type, int setting,
IMSL_SET_TRACEBACK, Imsl_error type, int setting,
IMSL_FULL_TRACEBACK, int setting,
IMSL_GET_PRINT, Imsl_error type, int *psetting,
IMSL_GET_STOP, Imsl_error type, int *psetting,
IMSL_GET_TRACEBACK, Imsl_error type, int *psetting,
IMSL_SET_ERROR_FILE, FILE *file,
IMSL_GET_ERROR_FILE, FILE **pfile,
IMSL_ERROR_MSG_PATH, char *path,
IMSL_ERROR_MSG_NAME, char *name,
IMSL_ERROR_PRINT_PROC, Imsl_error_print_proc print_proc,
0)
Optional Arguments
IMSL_SET_PRINT, Imsl_error type, int setting (Input)
Printing of type type error messages is turned off if setting is 0; otherwise, printing is turned on.
Default: Printing turned on for IMSL_WARNING, IMSL_FATAL, IMSL_TERMINAL, IMSL_FATAL_IMMEDIATE, and IMSL_WARNING_IMMEDIATE messages
IMSL_SET_STOP, Imsl_error type, int setting (Input)
Stopping on type type error messages is turned off if setting is 0; otherwise, stopping is turned on.
Default: Stopping turned on for IMSL_FATAL, IMSL_TERMINAL, and IMSL_FATAL_IMMEDIATE messages
IMSL_SET_TRACEBACK, Imsl_error type, int setting (Input)
Printing of a traceback on type type error messages is turned off if setting is 0; otherwise, printing of the traceback turned on.
Default: Traceback turned off for all message types
IMSL_FULL_TRACEBACK, int setting (Input)
Only documented functions are listed in the traceback if setting is 0; otherwise, internal function names also are listed.
Default: Full traceback turned off
IMSL_GET_PRINT, Imsl_error type, int *psetting (Output)
Sets the integer pointed to by psetting to the current setting for printing of type type error messages.
IMSL_GET_STOP, Imsl_error type, int *psetting (Output)
Sets the integer pointed to by psetting to the current setting for stopping on type type error messages.
IMSL_GET_TRACEBACK, Imsl_error type, int *psetting (Output)
Sets the integer pointed to by psetting to the current setting for printing of a traceback for type type error messages.
IMSL_SET_ERROR_FILE, FILE *file (Input)
Sets the error output file.
Default: file = stderr
IMSL_GET_ERROR_FILE, FILE **pfile (Output)
Sets the FILE * pointed to by pfile to the error output file.
IMSL_ERROR_MSG_PATH, char *path (Input)
Sets the error message file path. On UNIX systems, this is a colon-separated list of directories to be searched for the file containing the error messages.
Default: system dependent
IMSL_ERROR_MSG_NAME, char *name (Input)
Sets the name of the file containing the error messages.
Default: file = “imslerr.bin
IMSL_ERROR_PRINT_PROC, Imsl_error_print_proc print_proc (Input)
Sets the error printing function. The procedure print_proc has the form void print_proc (Imsl_error type, long code, char *function_name, char *message).
In this case, type is the error message type number (IMSL_FATAL, etc.), code is the error message code number (IMSL_MAJOR_VIOLATION, etc.), function_name is the name of the function setting the error, and message is the error message to be printed. If print_proc is NULL, then the default error printing function is used.
Return Value
The return value for this function is void.
Description
This function allows the error handling system to be customized.
If multiple threads are used then default settings are valid for each thread but can be altered for each individual thread. See Example 3 and Example 4 for multithreaded examples.
Examples
Example 1
In this example, the IMSL_TERMINAL print setting is retrieved. Next, stopping on IMSL_TERMINAL errors is turned off, then output to standard output is redirected, and an error is deliberately caused by calling imsl_error_options with an illegal value.
 
#include <imsl.h>
#include <stdio.h>
 
int main()
{
int setting;
/* Turn off stopping on IMSL_TERMINAL */
/* error messages and write error */
/* messages to standard output */
imsl_error_options(IMSL_SET_STOP, IMSL_TERMINAL, 0,
IMSL_SET_ERROR_FILE, stdout,
0);
/* Call imsl_error_options() with */
/* an illegal value */
imsl_error_options(-1);
/* Get setting for IMSL_TERMINAL */
imsl_error_options(IMSL_GET_PRINT, IMSL_TERMINAL, &setting,
0);
printf("IMSL_TERMINAL error print setting = %d\n", setting);
}
Output
 
*** TERMINAL Error from imsl_error_options. There is an error with
*** argument number 1. This may be caused by an incorrect number of
*** values following a previous optional argument name.
 
IMSL_TERMINAL error print setting = 1
Example 2
In this example, IMSL’s error printing function has been substituted for the standard function. Only the first four lines are printed below.
 
#include <imsl.h>
#include <stdio.h>
 
void print_proc(Imsl_error, long, char*, char*);
 
int main()
{
/* Turn off tracebacks on IMSL_TERMINAL */
/* error messages and use a custom */
/* print function */
imsl_error_options(IMSL_ERROR_PRINT_PROC, print_proc,
0);
/* Call imsl_error_options() with an */
/* illegal value */
imsl_error_options(-1);
}
 
void print_proc(Imsl_error type, long code, char *function_name,
char *message)
{
printf("Error message type %d\n", type);
printf("Error code %d\n", code);
printf("From function %s\n", function_name);
printf("%s\n", message);
}
Output
 
Error message type 5
Error code 103
From function imsl_error_options
There is an error with argument number 1. This may be caused by an incorrect number of values following a previous optional argument name.
Example 3
In this example, two threads are created and error options is called within each thread to set the error handling options differently for each thread. Since we expect to generate terminal errors in each thread, we must turn off stopping on terminal errors for each thread. See Example 4 for a similar example using WIN32 threads. Note since multiple threads are executing, the order of the errors output may differ on some systems.
 
#include <imsl.h>
#include <stdlib.h>
#include <pthread.h>
 
void *ex1(void* arg);
void *ex2(void* arg);
 
int main()
{
pthread_t thread1;
pthread_t thread2;
 
/* Create two threads. */
if (pthread_create(&thread1, NULL ,ex1, (void *)NULL) != 0)
perror("pthread_create"), exit(1);
if (pthread_create(&thread2, NULL ,ex2, (void *)NULL) != 0)
perror("pthread_create"), exit(1);
 
/* Wait for threads to finish. */
if (pthread_join(thread1, NULL) != 0)
perror("pthread_join"),exit(1);
if (pthread_join(thread2, NULL) != 0)
perror("pthread_join"),exit(1);
}
 
void *ex1(void* arg)
{
float res;
/* Call imsl_error_options to set the error handling
* options for this thread. Notice that the error printing
* function wil lbe user defined for this thread only. */
imsl_error_options(
IMSL_SET_STOP,
IMSL_TERMINAL, 0,
0);
res = imsl_f_beta(-1.0, .5);
}
 
void *ex2(void* arg)
{
float res;
 
/* Call imsl_error_options to set the error handling
* options for this thread. */
imsl_error_options(
IMSL_SET_STOP,
IMSL_TERMINAL, 0,
IMSL_SET_TRACEBACK,
IMSL_TERMINAL, 1,
0);
res = imsl_f_gamma(-1.0);
}
 
Output
 
*** TERMINAL Error from imsl_f_beta. Both "x" = -1.000000e+00 and "y" =
*** 5.000000e-01 must be greater than zero.
 
 
*** TERMINAL Error from imsl_f_gamma. The argument for the function can not
*** be a negative integer. Argument "x" = -1.000000e+00.
 
Here is a traceback of the calls in reverse order.
Error Type Error Code Routine
---------- ---------- -------
IMSL_TERMINAL IMSL_NEGATIVE_INTEGER imsl_f_gamma
USER
Example 4
In this example the WIN32 API is used to demonstrate the same functionality as shown in Example 3 above. Note since multiple threads are executing, the order of the errors output may differ on some systems.
 
#include <imsl.h>
#include <stdio.h>
#include <windows.h>
 
DWORD WINAPI ex1(void *arg);
DWORD WINAPI ex2(void *arg);
 
int main(int argc, char* argv[])
{
HANDLE thread[2];
 
thread[0] = CreateThread(NULL, 0, ex1, NULL, 0, NULL);
thread[1] = CreateThread(NULL, 0, ex2, NULL, 0, NULL);
 
WaitForMultipleObjects(2, thread, TRUE, INFINITE);
system("pause");
 
}
 
DWORD WINAPI ex1(void *arg)
{
float res;
 
/* Call imsl_error_options to set the error handling
* options for this thread. */
imsl_error_options(
IMSL_SET_STOP,
IMSL_TERMINAL, 0,
0);
res = imsl_f_beta(-1.0, .5);
}
 
DWORD WINAPI ex2(void *arg)
{
float res;
 
/* Call imsl_error_options to set the error handling
* options for this thread. Notice that tracebacks are
* turned on for IMSL_TERMINAL errors. */
 
imsl_error_options(
IMSL_SET_STOP,
IMSL_TERMINAL, 0,
IMSL_SET_TRACEBACK,
IMSL_TERMINAL, 1,
0);
res = imsl_f_gamma(-1.0);
}
Output
 
*** TERMINAL Error from imsl_f_gamma. The argument for the function can not
*** be a negative integer. Argument "x" = -1.000000e+00.
 
Here is a traceback of the calls in reverse order.
Error Type Error Code Routine
---------- ---------- -------
IMSL_TERMINAL IMSL_NEGATIVE_INTEGER imsl_f_gamma
USER
 
*** TERMINAL Error from imsl_f_beta. Both "x" = -1.000000e+00 and "y" =
*** 5.000000e-01 must be greater than zero.