9.3. Taking Exception to Yourself

Having discussed how we handle exceptions generated by Perl, it's time to talk about how we make exceptions of our own. You're already used to the most basic exception-generating method, which is to call die. The arguments are printed, and your program exits with a nonzero return code. (Just which nonzero return code is documented in gory detail under perldoc -f die.)

You may see some additional text output by die, such as the line number of code it died on. If instead it says (eval 13), it's telling you that it was executing the thirteenth call to eval and prints the line number relative to the evaled code, not the program containing the eval. If it says <FOO> chunk 42, it means that you had the filehandle ...

Get Perl Debugged now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.