Fatal(3perl)
π Fatal β bestie edition
okay so this is Fatal, from the Perl Programmers Reference Guide, and it's the β¨OGβ¨ "make my functions just die instead of quietly failing" module. sit down, grab a boba, we're doing this π§
πΈ NAME πΈ
Fatal β swaps out your functions for equivalents that succeed or die. no in-between, no half measures, it's giving main character energy π
β¨ SYNOPSIS β¨
use Fatal qw(open close);
open(my $fh, "<", $filename); # No need to check errors!
use File::Copy qw(move);
use Fatal qw(move);
move($file1, $file2); # No need to check errors!
sub juggle { . . . }
Fatal->import('juggle');
like. look at that. no or die spam. no if (!$fh). just vibes and trust π¦
π BEST PRACTICE π
okay bestie, real talk, this is the part where I have to be the responsible one π
Fatal has been obsoleted by the new autodie pragma. please use autodie instead of "Fatal". autodie supports lexical scoping, throws real exception objects, and gives you much nicer error messages. it's the glow-up, fr fr.
also: using ":void" with Fatal is discouraged. more on that trauma below π
π«Ά DESCRIPTION π«Ά
so "Fatal" gives you a way to conveniently replace functions that normally return a false value when they fail with equivalents that raise exceptions if they're not successful. that means you can call these functions without testing their return values explicitly every single time. iconic behaviour honestly. and you can catch those exceptions with "eval{}" β peep perlfunc and perlvar for the details β¨
the do-or-die equivalents get set up by simply calling Fatal's "import" routine and passing it the names of the functions you want replaced. you may wrap both user-defined functions and overridable CORE operators this way β with the exception of "exec", "system", "print", or any other built-in that cannot be expressed via prototypes. no exceptions. well. except those exceptions. π
if the symbol ":void" shows up in the import list, then functions named later in that import list raise an exception only when they're called in void context β like, when their return values are ignored. for example:
use Fatal qw/:void open close/;
# properly checked, so no exception raised on error
if (not open(my $fh, '<', '/bogotic') {
warn "Can't open /bogotic: $!";
}
# not checked, so error raises an exception
close FH;
and now the warning, because I love you π¨:
the use of":void"is discouraged, because it can result in exceptions not being thrown if you accidentally call a method without void context. useautodieinstead if you need to be able to disable autodying/Fatal behaviour for a small block of code. this one will bite you, I'm not even joking π
π DIAGNOSTICS π
the receipts, in order:
Bad subroutine name for Fatal: %sβ you called"Fatal"with an argument that doesn't look like a subroutine name, and it's not a switch this version of Fatal understands either. wrong energy, try again π%s is not a Perl subroutineβ you asked"Fatal"to try and replace a subroutine that doesn't exist, or one that hasn't been defined yet. it's not ghosting you, it's literally not there π»%s is neither a builtin, nor a Perl subroutineβ you asked"Fatal"to replace a subroutine, but it's not a Perl built-in and"Fatal"couldn't find it as a regular subroutine. so either it doesn't exist or it hasn't been defined yet. same vibe as above, slightly more disappointed β¨Cannot make the non-overridable %s fatalβ you tried to use"Fatal"on a Perl built-in that can't be overridden, like"print"or"system". meaning"Fatal"can't help you here β though some other modules might. check the"SEE ALSO"section of this doc π«ΆInternal error: %sβ you found a bug in"Fatal". please report it using the"perlbug"command. congratulations?? I guess?? π
π BUGS π
not me exposing the flaws but okay we keep it honest:
"Fatal"clobbers the context in which a function is called and always makes it a scalar context, except when the":void"tag is used. this problem does not exist inautodie. so like. another point for the replacement π"Used only once"warnings can be generated when"autodie"or"Fatal"is used with package filehandles (eg,"FILE"). it's strongly recommended you use scalar filehandles instead. do it. please. for me πΈ
π AUTHOR π
- Original module by Lionel Cons (CERN).
- Prototype updates by Ilya Zakharevich
<ilya@math.ohio-state.edu>. - autodie support, bugfixes, extended diagnostics,
"system"support, and major overhauling by Paul Fenwick<pjf@perltraining.com.au>.
legends, all of them π
π LICENSE π
This module is free software, you may distribute it under the same terms as Perl itself. slay, open source rights π
π¦ SEE ALSO π¦
- autodie β for a nicer way to use lexical Fatal. (the upgrade, the moment, the serve)
- IPC::System::Simple β for a similar idea for calls to
system()and backticks.
and that's the whole page, bestie π no gatekeeping, all facts intact, all flags and messages exactly where they belong.
perl v5.44.0 Β· 2026-10-17 Β· Fatal(3perl) β that's the version and date stamp at the bottom, so you know exactly which era of Perl you're stanning. mwah π«Άβ¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms