Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

die and croak

Status
Not open for further replies.

Corwinsw

Programmer
Sep 28, 2005
117
BG
Hi guys,
Today another question torments my brain. :)
Damian Conway says in his book "Perl best practices" that is better to use croak instead of die. I also have seen that in other places, as hacking around.
So what is the practical difference between die and croak?

Corwin
 
use die in your scripts and croak in your modules. You need to have "use Carp;" before you can croak.

The difference is to do with from where the error appears to come. You would not normally want an error message from a module to quote the module name and line number, rather the calling script's name and line number.

I leave it out while developing and, once I'm happyy that the module is stable and debugged, I turn it on, expecting all further errors to be usage errors from the caller.

Yours,

fish

["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top