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. use autodie instead 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 in autodie. 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