Emits a warning, usually by printing it to STDERR
. warn
interprets its operand LIST in the same way as die
, but is slightly different in what it defaults to when LIST is empty or makes an empty string. If it is empty and $@
already contains an exception value then that value is used after appending "\t...caught"
. If it is empty and $@
is also empty then the string "Warning: Something's wrong"
is used.
By default, the exception derived from the operand LIST is stringified and printed to STDERR
. This behaviour can be altered by installing a $SIG{__WARN__}
handler. If there is such a handler then no message is automatically printed; it is the handler's responsibility to deal with the exception as it sees fit (like, for instance, converting it into a die
). Most handlers must therefore arrange to actually display the warnings that they are not prepared to deal with, by calling warn
again in the handler. Note that this is quite safe and will not produce an endless loop, since __WARN__
hooks are not called from inside one.
You will find this behavior is slightly different from that of $SIG{__DIE__}
handlers (which don't suppress the error text, but can instead call