4.1 Error Handling

When an error occurs during a call to any of the DEC C RTL functions, the function returns an unsuccessful status. Many RTL routines also set the external variable errno to a value that indicates the reason for the failure. You should always check the return value for an error situation.

The <errno.h> header file declares errno and symbolically defines the possible error codes. By including the <errno.h> header file in your program, you can check for specific error codes after a DEC C RTL function call.

At program startup, the value of errno is 0. The value of errno can be set to a nonzero value by many DEC C RTL functions. It is not reset to 0 by any DEC C RTL function, so it is only valid to use errno after a DEC C RTL function call has been made and a failure status returned. Table 4-2 lists the symbolic values that may be assigned to errno by the DEC C RTL.

Table 4-2 The Error Code Symbolic Values

Symbolic Constant  Description 
E2BIG  Argument list too long 
EACCES  Permission denied 
EADDRINUSE  Address already in use 
EADDRNOTAVAIL  Can't assign requested address 
EAFNOSUPPORT  Address family not supported 
EAGAIN  No more processes 
EALIGN  Alignment error 
EALREADY  Operation already in progress 
EBADF  Bad file number 
EBADCAT  Bad message catalogue format 
EBADMSG  Corrupted message detected 
EBUSY  Mount device busy 
ECANCELED  Operation canceled 
ECHILD  No children 
ECONNABORTED  Software caused connection abort 
ECONNREFUSED  Connection refused 
ECONNRESET  Connection reset by peer 
EDEADLK  Resource deadlock avoided 
EDESTADDRREQ  Destination address required 
EDOM  Math argument 
EDQUOT  Disk quota exceeded 
EEXIST  File exists 
EFAIL  Cannot start operation 
EFAULT  Bad address 
EFBIG  File too large 
EFTYPE  Inappropriate operation for file type 
EHOSTDOWN  Host is down 
EHOSTUNREACH  No route to host 
EIDRM  Identifier removed 
EILSEQ  Illegal byte sequence 
EINPROGRESS  Operation now in progress 
EINPROG  Asynchronous operation in progress 
EINTR  Interrupted system call 
EINVAL  Invalid argument 
EIO  I/O error 
EISCONN  Socket is already connected 
EISDIR  Is a directory 
ELOOP  Too many levels of symbolic links 
EMFILE  Too many open files 
EMLINK  Too many links 
EMSGSIZE  Message too long 
ENAMETOOLONG  File name too long 
ENETDOWN  Network is down 
ENETRESET  Network dropped connection on reset 
ENETUNREACH  Network is unreachable 
ENFILE  File table overflow 
ENOBUFS  No buffer space available 
ENODEV  No such device 
ENOENT  No such file or directory 
ENOEXEC  Exec format error 
ENOLCK  No locks available 
ENOMEM  Not enough core 
ENOMSG  No message of desired type 
ENOPROTOOPT  Protocol not available 
ENOSPC  No space left on device 
ENOSYS  Function not implemented 
ENOTBLK  Block device required 
ENOTCONN  Socket is not connected 
ENOTDIR  Not a directory 
ENOTEMPTY  Directory not empty 
ENOTSOCK  Socket operation on non-socket 
ENOTSUP  Function not implemented 
ENOTTY  Not a typewriter 
ENWAIT  No waiting processes 
ENXIO  No such device or address 
EOPNOTSUPP  Operation not supported on socket 
EPERM  Not owner 
EPFNOSUPPORT  Protocol family not supported  
EPIPE  Broken pipe 
EPROCLIM  Too many processes 
EPROTONOSUPPORT  Protocol not supported 
EPROTOTYPE  Protocol wrong type for socket 
ERANGE  Result too large 
EREMOTE  Too many levels of remote in path 
EROFS  Read-only file system 
ESHUTDOWN  Can't send after socket shutdown 
ESOCKTNOSUPPORT  Socket type not supported 
ESPIPE  Illegal seek 
ESRCH  No such process 
ESTALE  Stale NFS file handle 
ETIMEDOUT  Connection timed out 
ETOOMANYREFS  Too many references: can't splice  
ETXTBSY  Text file busy 
EUSERS  Too many users 
EVMSERR  OpenVMS-specific non-translatable error code 
EWOULDBLOCK  I/O operation would block channel 
EXDEV  Cross-device link 

You can translate the error codes to a message, similar to that found in UNIX systems, by using the perror or strerror function. If errno is set to EVMSERR, perror cannot translate the error code, and prints the following message, followed by the OpenVMS error message associated with the value:

%s:nontranslatable vms error code: xxxxxx vms message:

In the message, %s is the string you supply to perror; xxxxxx is the OpenVMS condition value.

If errno is set to EVMSERR, then the OpenVMS condition value is available in the vaxc$errno variable declared in the <errno.h> header file. The vaxc$errno variable is guaranteed to have a valid value only if errno is set to EVMSERR; if errno is set to a value other than EVMSERR, the value of vaxc$errno is undefined.

See also the strerror function in the Reference Section for another way to translate error codes.


Previous Page | Next Page | Table of Contents | Index