No::Worries::Die(3)
β¨ NAME β¨
okay bestie, meet No::Worries::Die(3) β your User Contributed Perl Documentation page for No::Worries::Die, and its whole brand is literally error handling without worries π
π οΈ SYNOPSIS π οΈ
here's the vibe in code form:
use No::Worries::Die qw(dief handler);
open($fh, "<", $path) or dief("cannot open(%s): %s", $path, $!);
... not reached in case of failure ...
$ ./myprog
myprog: cannot open(foo): No such file or directory
$ NO_WORRIES=confess ./myprog
myprog: cannot open(foo): No such file or directory at myprog line 16
main::test() called at ./myprog line 19
πΈ DESCRIPTION πΈ
okay so this module makes error handling so much easier by giving you a convenient wrapper around die() with a sprintf()-like API. dief() is to die() what printf() is to print(), and on top of that it also trims leading and trailing spaces. obsessed π
it also provides a handler for die() that prepends a prefix ($No::Worries::Die::Prefix) to all errors. it also uses the "NO_WORRIES" environment variable to find out if Carp's croak() or confess() should be used instead of die(). and finally, the wrapper can be told to also log errors to syslog (see $No::Worries::Die::Syslog). π
you can install this handler simply by importing it:
use No::Worries::Die qw(dief handler);
alternatively, it can be installed "manually" like this:
use No::Worries::Die qw(dief);
$SIG{__DIE__} = \&No::Worries::Die::handler;
π¦ FUNCTIONS π¦
this module provides the following functions (none of them are exported by default, just so you know):
dief(MESSAGE)β report an error described by the given MESSAGEdief(FORMAT, ARGUMENTS...)β same idea, but with asprintf()-like APIhandler(MESSAGE)β a$SIG{__DIE__}compatible error handler (this function cannot be imported)
π GLOBAL VARIABLES π
this module uses the following global variables (none of them are exported):
$Prefixβ prefix to prepend to all errors (default: the program name)$Syslogβ true if errors should also be sent to syslog usingNo::Worries::Syslog'ssyslog_error()(default: false)
π ENVIRONMENT VARIABLES π
this module uses the "NO_WORRIES" environment variable to control how errors should be reported. supported values are:
"croak"βCarp'scroak()will be used instead ofdie()"confess"βCarp'sconfess()will be used instead ofdie()
π SEE ALSO π
go give these a look, bestie: Carp, No::Worries, No::Worries::Syslog, No::Worries::Warn.
π AUTHOR π
Lionel Cons <http://cern.ch/lionel.cons>
Copyright (C) CERN 2012-2019
mwah π this page is from perl v5.32.1, dated 2021-10-18 β and that's the whole manual, bestie. slay β¨
π¦ where this page comes from
- epel 9: perl-No-Worries 1.7-1.el9 Β· GPL+ or Artistic
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms