What is the difference between die and exit in perl?

Showing Answers 1 - 2 of 2 Answers

nitashaa

  • Jul 15th, 2008
 

die("couldnot open filen"); ---> terminate the program with customized message.
die -> terminates with last system error message.
exit(0) or exit; for success 
exit(1); failure
die function never accepts number as argument.It always accepts string or nothing.
die function always terminate prgram with error message wheras exit just terminates

wow_suraj

  • Jun 17th, 2009
 

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

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

3) die outputs a message
exit does not.

felix

  • Nov 21st, 2011
 

There is not same it must be difference . I am sure it must difference but same action perform.but returning a value difference may be like string variable what ever may be

  Was this answer useful?  Yes

vasava pv

  • Oct 7th, 2012
 

die function was print a error message and exit function does not ... Otherwise both are same functionality

  Was this answer useful?  Yes

vinod

  • Jun 20th, 2013
 

exit will simply end the program but die will print the message before ending the program

  Was this answer useful?  Yes

george

  • Oct 11th, 2013
 

Die will print a message to the std err, then exit with a non-zero return code. You dont control the return code and you are stuck with the text going to the std err.

Exit will terminate with a specified return code.

I recommend a print and exit instead of a die. For instance,

print "descriptive text
";
exit(18);

You get to control if the text goes to std err or out or a log. You can also control the return code value. Die is fast and convenient, but print and exit give you much more control.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions