next up previous contents
Next: Using the || Logical Up: Handling Errors and Signals Previous: Checking for Errors

Using errno

When an error occurs, it is common practice for UNIX-based functions and programs to set a variable called errno to reflect which error has occurred. If errno=2, then your script tried to access a directory or file that did not exist. Table 13.1 lists 10 possible values the errno variable can take, but there are hundreds more. If you are interested in seeing all the possible error values, run the program,err1.pl:

for ($! = 1; $! <= 10000; $!++) {

    $errText = $!;

    chomp($errText);

    printf("%04d: %s\n", $!, $errText) if $! ne "Unknown Error";

}

The program operates as follows:

There are Ten Possible Values for errno:

1.
Operation not permitted
2.
No such file or directory
3.
No such process
4.
Interrupted function call

5.
Input/output error

6.
No such device or address

7.
Arg list too long

8.
Exec format error

9.
Bad file descriptor

10.
No child processes

next up previous contents
Next: Using the || Logical Up: Handling Errors and Signals Previous: Checking for Errors
dave@cs.cf.ac.uk