Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: different between die and exit

by mr_mischief (Monsignor)
on Feb 26, 2009 at 00:30 UTC ( [id://746410] : note . print w/replies, xml ) Need Help??


in reply to different between die and exit

I'll defer to ikegami's (amended) reply for the differences between those two items. For completeness, I'll also mention another more rarely used option and explain their relative usefulness.

One may also wish to compare and contrast POSIX::_exit which exits the program immediately. It does not run destructors or END blocks and doesn't flush buffered I/O streams. Both die and exit do those things before they cause the program to exit to the OS.

The behavior usually wanted is that of die(). You might not be catching the condition now, but you may want to later.

Sometimes exit() is preferred. You might want to exit in a way that specifically always exits the program and ends the process. You might want to write your error condition somewhere other than STDERR then return a specific error code to the parent program. I've written some network server code that uses print() and exit() to do just that.

Only quite rarely will POSIX::_exit() be needed. Most people will probably never find a good reason to use it, but it's available in case it is needed.