=over
=item die LIST
Outside an C, prints the value of LIST to C and exits with
the current value of C (errno). If C is C, exits with the value of
CE 8)> (backtick `command` status). If CE 8)>
is C, exits with C. Inside an C the error message is stuffed into
C and the C is terminated with the undefined value. This makes
C the way to raise an exception.
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"
If the value of EXPR does not end in a newline, the current script line
number and input line number (if any) are also printed, and a newline
is supplied. Hint: sometimes appending C to your message
will cause it to make better sense when the string C is
appended. Suppose you are running script "canasta".
die "/etc/games is no good";
die "/etc/games is no good, stopped";
produce, respectively
/etc/games is no good at canasta line 123.
/etc/games is no good, stopped at canasta line 123.
See also C and C.
If LIST is empty and C already contains a value (typically from a
previous eval) that value is reused after appending C.
This is useful for propagating exceptions:
eval { ... };
die unless $@ =~ /Expected exception/;
If C is empty then the string C is used.
You can arrange for a callback to be run just before the C does
its deed, by setting the C hook. The associated handler
will be called with the error text and can change the error message, if
it sees fit, by calling C again. See L for details on
setting C entries, and L for some examples.
Note that the C hook is called even inside eval()ed
blocks/strings. If one wants the hook to do nothing in such
situations, put
die @_ if $^S;
as the first line of the handler (see L).
=back