No::Worries::Die(3)

πŸ“¦
version 1.7 Β· 4 versions
, in epel 9

✨ 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 MESSAGE
  • dief(FORMAT, ARGUMENTS...) β€” same idea, but with a sprintf()-like API
  • handler(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 using No::Worries::Syslog's syslog_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's croak() will be used instead of die()
  • "confess" β€” Carp's confess() will be used instead of die()

πŸ‘‘ 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