Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: different between die and exit

by ikegami (Patriarch)
on Feb 23, 2009 at 04:17 UTC ( [id://745700] : note . print w/replies, xml ) Need Help??


in reply to different between die and exit

die is used to throw an exception (catchable using eval).
exit is used to exit the process.

die will set the error code based on $! or $? if the exception is uncaught.
exit will set the error code based on its argument.

And of course,
die outputs a message
exit does not.

Update: Added "catchable" bit by request of ysth.

Replies are listed 'Best First'.
Re^2: different between die and exit (or the lack thereof)
by ikegami (Patriarch) on Feb 23, 2009 at 15:46 UTC

    One important similarity:
    die and exit both unwind the stack, calling destructors and END blocks when necessary.