On 8/13/07, Robert Hicks <[EMAIL PROTECTED]> wrote: > I typically "use Carp;" and change my "die" and "warn" statements to > "croak" and "carp". I have read a couple places croak/carp are a little > better at telling you what and where than the standard die/warn. > > Robert
The question of whether to use croak/carp or die/warn is one of where the error is. If the caller of the function passed in bad data croak/carp is the right choice. If the problem is with the current code or things it is calling then die/warn is the right choice. For instance, say I have a library function that takes the name of a file to write to and that file is not writable, this is not the library function's fault. It is the fault of the person who called the library function. If we were to use die then the file and line number would report the location in the library where the code failed, but this won't help the user find where he passed bad information. In this case croak is the appropriate choice. Keeping with this same example, lets say that this function also copies a file to another location and then does a chksum to make sure that the files are still the same and the chksum comes back wrong. In this case the issue is probably with the library code, so telling the user that his/her call to the function failed is fairly useless (he/she can't change his/her code to fix the problem), so die would be the right answer. However, if you really want to get the best picture of what was going on you should use confess/cluck instead of croak/carp or die/warn. It will spit out a full stack trace. Most of the time this is overkill (the problem is usually with either the caller of the function or the function itself), but it can be handy. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/