What's the difference between Carp/Croak, Cluck/Confess, and verbose options?

The problem with your example is that all your subs are in the same package (the default package: main). That's not the use case that Carp was designed for.

Carp is intended to be used in modules. The reason is that when a module encounters a problem, it's often because the module's caller passed it bad data. Therefore, instead of reporting the line where the module discovered the problem, it's usually more useful to report the line where the module was called (from code outside the module). That's what the functions exported by Carp do.

There are 2 sets of yes/no options. The function can be fatal (like die) or nonfatal (like warn). It can report just the line where the function was called, or it can report a full backtrace.

         Fatal  Backtrace
carp       N        N
cluck      N        Y
croak      Y        N
confess    Y        Y

The verbose option forces backtraces on. That is, it makes carp act like cluck, and croak act like confess. You can use that when you realize that you need more debugging information, but don't want to change the code to use confess.


Carp is better than warn/die in that it will display the file and line of what called the function throwing an error, rather than simply where the error was thrown. This can often be useful for libraries. (For instance, a database library should probably throw errors indicating where the erroneous database call is, rather than indicating a line within itself.)

carp, cluck, croak, and confess give you four combinations of options:

  • carp: not fatal, no backtrace
  • cluck: not fatal, with backtrace
  • croak: fatal, no backtrace
  • confess: fatal, with backtrace