1No::Worries::Die(3) User Contributed Perl Documentation No::Worries::Die(3)
2
3
4
6 No::Worries::Die - error handling without worries
7
9 use No::Worries::Die qw(dief handler);
10
11 open($fh, "<", $path) or dief("cannot open(%s): %s", $path, $!);
12 ... not reached in case of failure ...
13
14 $ ./myprog
15 myprog: cannot open(foo): No such file or directory
16
17 $ NO_WORRIES=confess ./myprog
18 myprog: cannot open(foo): No such file or directory at myprog line 16
19 main::test() called at ./myprog line 19
20
22 This module eases error handling by providing a convenient wrapper
23 around die() with sprintf()-like API. dief() is to die() what printf()
24 is to print() with, in addition, the trimming of leading and trailing
25 spaces.
26
27 It also provides a handler for die() that prepends a prefix
28 ($No::Worries::Die::Prefix) to all errors. It also uses the
29 "NO_WORRIES" environment variable to find out if Carp's croak() or
30 confess() should be used instead of die(). Finally, the wrapper can be
31 told to also log errors to syslog (see $No::Worries::Die::Syslog).
32
33 This handler can be installed simply by importing it:
34
35 use No::Worries::Die qw(dief handler);
36
37 Alternatively, it can be installed "manually":
38
39 use No::Worries::Die qw(dief);
40 $SIG{__DIE__} = \&No::Worries::Die::handler;
41
43 This module provides the following functions (none of them being
44 exported by default):
45
46 dief(MESSAGE)
47 report an error described by the given MESSAGE
48
49 dief(FORMAT, ARGUMENTS...)
50 idem but with sprintf()-like API
51
52 handler(MESSAGE)
53 $SIG{__DIE__} compatible error handler (this function cannot be
54 imported)
55
57 This module uses the following global variables (none of them being
58 exported):
59
60 $Prefix
61 prefix to prepend to all errors (default: the program name)
62
63 $Syslog
64 true if errors should also be sent to syslog using
65 No::Worries::Syslog's syslog_error() (default: false)
66
68 This module uses the "NO_WORRIES" environment variable to control how
69 errors should be reported. Supported values are:
70
71 "croak"
72 Carp's croak() will be used instead of die()
73
74 "confess"
75 Carp's confess() will be used instead of die()
76
78 Carp, No::Worries, No::Worries::Syslog, No::Worries::Warn.
79
81 Lionel Cons <http://cern.ch/lionel.cons>
82
83 Copyright (C) CERN 2012-2019
84
85
86
87perl v5.36.0 2023-01-20 No::Worries::Die(3)