Ingy döt Net


The Thought Behind


The primary goal behind the errors module is to finally add error handling to Perl that people actually want to use.

For that to happen it needs to be simple yet full featured. It needs to be sexy, but also to Just Work.

In my opinion, the best part of the module is the name. You can simply say:

    use errors;

And all the right stuff should happen.

This will hopefully lead to the following prelude in Perl programs and modules:

    use strict;
    use warnings;
    use errors;

Moving Parts

The module is designed to do 3 primary things when you use it.

  • Export a try/catch interface.

  • Provide a base class for error objects.

  • Provide a hierarchy of standard/system error classes.

The first two things are done by a lot of modules. The third, not so much.

Under the hood, coerces errors into the appropriate objects, and tries to play nice (be interoperable) with the other error modules.

Other Modules

errors should play nice with the following modules:


  • Exception-Class

  • autodie

Python Exceptions

I first got interested in doing an exception module, after porting lots of code back and forth between Python and Perl. Python code tends to use exceptions a lot, so they probably got it pretty much right.

Here's some basic Python code:

    class FooError(Exception):
    class FooFooError(FooError):
    class BarError(Exception):

    except FooError, BarError as e:
    except RuntimeError as e:

Notable things:

Python encourages you to make your own error subclasses, and catch them specifically by name.

Python gives you an else clause. Evidently, tryelse is an idiom just like ifelse.

An except (think catch) clause lets you name one or many classes to match on. It also allows no selection classes, which means match on any.

The errors module will default to Python semantics as much as reasonable.

At first glance seems almost equivalent to the Python way, just with slightly differing names:

    - The default class is Error, not Exception.
    - Use throw instead of raise
    - Use 'catch Name with' instead of 'except Name:'
    - Use except as default (like catch with no named class selector)
    - Use otherwise instead of else (because else is Perl keyword)

It turns out this is not quite right. In the semantics of 'except' and 'otherwise' are quite different; 'otherwise' is like python except, 'except' has just plain weird semantics, and there is no analog for the Python 'else'.

Therefore, while the errors module probably needs to coexist and be aware of, it will not attempt to follow its exact syntax and semantics.

There is a module called Exceptions to which the Exception (non plural) is indexed. It is only at version 0.01 and has no documentation. It appears to be dead.

This is fortunate because we can use 'Exception' as our base class for all errors. Using 'Error' would be a mistake because we could not interoperate with code that uses

Python also uses 'Exception' as its root base class. Python also has the convention that subclasses end with the word 'Error'. Like this:

    # Define a subclass of Exception called MyError
    class MyError(Exception):


It seems like the following syntax fails for all the try/catch modules I've tried:

    try { try {...} catch ... {...}; } catch ... {...};

In other words, you can't try inside a try. This works fine in Python and should be made to work in Perl.


... more to come ...

I'm still working on getting the right design for this module, so that it can serve the Perl community well, and evolve with it.


Things I need to do:

  • Work with the authors/maintainers of and autodie

  • Look into how Perl 6 handles errors


Ingy döt Net <>


Copyright 2009-2014. Ingy döt Net.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.