10.5.6 Standard Library Error Messages

For some library functions, if an error occurs during the library function execution, an error code is set in the macro errno defined in the header file <errno.h> contained in the standard library.

Error messages are defined in the error codes so that error messages can be output. The following shows an example of an error message output program.

Example

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
main()
{
    FILE *fp;
 
    fp=fopen("file", "w");
    fp=NULL;
 
    fclose(fp);                       /* error occurred */
 
    printf("%s\n", strerror(errno));  /* print error message */
}

 

Description:

(1)

Since the file pointer of NULL is passed to the fclose function as an argument, an error will occur. In this case, an error code corresponding to errno is set.

(2)

The strerror function returns a pointer of the string literal of the corresponding error message when the error code is passed as an argument. An error message is output by specifying the output of the string literal of the printf function.

 

List of Standard Library Error Messages

Error No.

Error Message/Explanation

Functions to Set Error Code

0x22

(ERANGE)

Data out of range

An overflow occurred.

frexp, ldexp, modf, ceil, floor, fmod, atof, atoi,

atol, atoll, atolfixed, atolaccum, strtod, strtol,

strtoul, strtoll, strtoull, strtolfixed, strtolaccum,

perror, fprintf, fscanf, printf, scanf, sprintf,

sscanf, vfprintf, vprintf, vsprintf, acos, acosf,

asin, asinf, atan, atan2, atan2f, atanf, ceilf, cos,

cosf, cosh, coshf, exp, expf, floorf, fmodf,

ldexpf, log,log10, log10f, logf, modff, pow, powf,

sin, sinf, sinh, sinhf, sqrt, sqrtf, tan, tanf, tanh,

tanhf, fabs, fabsf, frexpf

0x21

(EDOM)

Data out of domain

Results for mathematical parameters are not defined.

acos, acosf, asin, asinf, atan, atan2, atan2f,

atanf, ceil, ceilf, cos, cosf, cosh, coshf, exp,

expf, floor, floorf, fmod, fmodf, ldexp, ldexpf,

log, log10, log10f, logf, modf, modff, pow, powf,

sin, sinf, sinh, sinhf, sqrt, sqrtf, tan, tanf, tanh,

tanhf, fabs, fabsf, frexp, frexpf

0x450

(ESTRN)

Too long string

The length of string literal exceeds 512 characters.

atof, atoi, atol, atoll, atolfixed, atolaccum, strtod,

strtol, strtoul, strtoll, strtoull, strtolfixed,

strtolaccum

0x04B0

(ECBASE)

Invalid radix

An invalid radix was specified.

strtol, strtoul, strtoll, strtoull

0x04B2

(ETLN)

Number too long

The specified number exceeds the number of significant digits.

atof, atolfixed, atolaccum, strtod, strtolfixed,

strtolaccum, fscanf, scanf, sscanf

0x04B4

(EEXP)

Exponent too large

The specified exponent exceeds three digits.

atof, strtod, fscanf, scanf, sscanf

0x04B6

(EEXPN)

Normalized exponent too large

The exponent exceeds three digits when the string literal is normalized to the IEEE standard decimal format.

atof, strtod, fscanf, scanf, sscanf

0x04BA

(EFLOATO)

Overflow out of float

A float-type decimal value is out of range (overflow).

fscanf, scanf, sscanf

0x04C4

(EFLOATU)

Underflow out of float

A float-type decimal value is out of range (underflow).

fscanf, scanf, sscanf

0x04E2

(EDBLO)

Overflow out of double

A double-type decimal value is out of range (overflow).

fscanf, scanf, sscanf

0x04EC

(EDBLU)

Underflow out of double

A double-type decimal value is out of range (underflow).

fscanf, scanf, sscanf

0x04F6

(ELDBLO)

Overflow out of long double

A long double-type decimal value is out of range (overflow).

fscanf, scanf, sscanf

0x0500

(ELDBLU)

Underflow out of long double

A long double-type decimal value is out of range (underflow).

fscanf, scanf, sscanf