Perl Programming/Keywords/die

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: DESTROY Keywords Next: do

The die keyword[edit | edit source]

The die comment raises an exception. If called inside an eval(), its message is stuffed into $@, and eval() returns with the undef. If the exception is outside of all enclosing eval()s, the uncaught exception prints LIST to STDERR and exits with a non-zero value. For a specific exit code, exit should be called.

Syntax[edit | edit source]

  die LIST

Examples[edit | edit source]

chdir '/usr/spool/news' or die "Cannot change to directory spool: $!\n"
Previous: DESTROY Keywords Next: do