{
    "mode": "perldoc",
    "parameter": "Fatal",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Fatal/json",
    "generated": "2026-06-15T13:13:04Z",
    "synopsis": "use Fatal qw(open close);\nopen(my $fh, \"<\", $filename);  # No need to check errors!\nuse File::Copy qw(move);\nuse Fatal qw(move);\nmove($file1, $file2); # No need to check errors!\nsub juggle { . . . }\nFatal->import('juggle');",
    "sections": {
        "NAME": {
            "content": "Fatal - Replace functions with equivalents which succeed or die\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Fatal qw(open close);\n\nopen(my $fh, \"<\", $filename);  # No need to check errors!\n\nuse File::Copy qw(move);\nuse Fatal qw(move);\n\nmove($file1, $file2); # No need to check errors!\n\nsub juggle { . . . }\nFatal->import('juggle');\n",
            "subsections": []
        },
        "BEST PRACTICE": {
            "content": "Fatal has been obsoleted by the new autodie pragma. Please use autodie in preference to \"Fatal\".\nautodie supports lexical scoping, throws real exception objects, and provides much nicer error\nmessages.\n\nThe use of \":void\" with Fatal is discouraged.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"Fatal\" provides a way to conveniently replace functions which normally return a false value\nwhen they fail with equivalents which raise exceptions if they are not successful. This lets you\nuse these functions without having to test their return values explicitly on each call.\nExceptions can be caught using \"eval{}\". See perlfunc and perlvar for details.\n\nThe do-or-die equivalents are set up simply by calling Fatal's \"import\" routine, passing it the\nnames of the functions to be replaced. You may wrap both user-defined functions and overridable\nCORE operators (except \"exec\", \"system\", \"print\", or any other built-in that cannot be expressed\nvia prototypes) in this way.\n\nIf the symbol \":void\" appears in the import list, then functions named later in that import list\nraise an exception only when these are called in void context--that is, when their return values\nare ignored. For example\n\nuse Fatal qw/:void open close/;\n\n# properly checked, so no exception raised on error\nif (not open(my $fh, '<', '/bogotic') {\nwarn \"Can't open /bogotic: $!\";\n}\n\n# not checked, so error raises an exception\nclose FH;\n\nThe use of \":void\" is discouraged, as it can result in exceptions not being thrown if you\n*accidentally* call a method without void context. Use autodie instead if you need to be able to\ndisable autodying/Fatal behaviour for a small block of code.\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "Bad subroutine name for Fatal: %s\nYou've called \"Fatal\" with an argument that doesn't look like a subroutine name, nor a\nswitch that this version of Fatal understands.\n\n%s is not a Perl subroutine\nYou've asked \"Fatal\" to try and replace a subroutine which does not exist, or has not yet\nbeen defined.\n\n%s is neither a builtin, nor a Perl subroutine\nYou've asked \"Fatal\" to replace a subroutine, but it's not a Perl built-in, and \"Fatal\"\ncouldn't find it as a regular subroutine. It either doesn't exist or has not yet been\ndefined.\n\nCannot make the non-overridable %s fatal\nYou've tried to use \"Fatal\" on a Perl built-in that can't be overridden, such as \"print\" or\n\"system\", which means that \"Fatal\" can't help you, although some other modules might. See\nthe \"SEE ALSO\" section of this documentation.\n\nInternal error: %s\nYou've found a bug in \"Fatal\". Please report it using the \"perlbug\" command.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "\"Fatal\" clobbers the context in which a function is called and always makes it a scalar context,\nexcept when the \":void\" tag is used. This problem does not exist in autodie.\n\n\"Used only once\" warnings can be generated when \"autodie\" or \"Fatal\" is used with package\nfilehandles (eg, \"FILE\"). It's strongly recommended you use scalar filehandles instead.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Original module by Lionel Cons (CERN).\n\nPrototype updates by Ilya Zakharevich <ilya@math.ohio-state.edu>.\n\nautodie support, bugfixes, extended diagnostics, \"system\" support, and major overhauling by Paul\nFenwick <pjf@perltraining.com.au>\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This module is free software, you may distribute it under the same terms as Perl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "autodie for a nicer way to use lexical Fatal.\n\nIPC::System::Simple for a similar idea for calls to \"system()\" and backticks.\n",
            "subsections": []
        }
    },
    "summary": "Fatal - Replace functions with equivalents which succeed or die",
    "flags": [],
    "examples": [],
    "see_also": []
}