3.2.27 die
die
Outside of an
eval
, this function prints the concatenated value
of Equivalent examples: die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news'; chdir '/usr/spool/news' or die "Can't cd to spool: $!\n" (The second form is generally preferred, since the important part is the chdir .) Within an eval , the function sets the $@ variable equal to the error message that would have been produced otherwise, and aborts the eval , which then returns the undefined value. The die function can thus be used to raise named exceptions that can be caught at a higher level in the program. See the section on the eval function later in this chapter.
If the final value of die "/etc/games is no good"; die "/etc/games is no good, stopped"; which produces, respectively: /etc/games is no good at canasta line 123. /etc/games is no good, stopped at canasta line 123.
If you want your own error messages reporting the filename and linenumber, use
the die '"', __FILE__, '", line ', __LINE__, ", phooey on you!\n"; This produces output like: "canasta", line 38, phooey on you! |
|