NAME

Exception::Simple - Exception classes and nothing more.

SYNOPSIS

use Exception::Simple;
use Scalar::Util qw/blessed/;

eval {
  throw Exception::Simple error => "Oh noes";
};

if (blessed $@ && $@->isa ('Exception::Simple')) {
  # Do something.
}

DESCRIPTION

Why another exception class? Well, as I was looking around CPAN for an exception class for my project, I found a lot of exception classes and none that suited my need; A simple exception class that didn't have any elaborate try/catch syntax, was easy to work with after exceptions were thrown, etc.

This module aims to do nothing but being an exception class. No sugar, no utility modules, just an exception class that should be flexible and easy to extend.

ATTRIBUTES

The module has a number of attributes that may be specified or even fills in automagically depending on how the exception is created. In addition to setting them as arguments to new/throw/rethrow, they may also be both retrieved and set through accessors. All optional attributes has a special has_attributename method that can be used to determine if they are set or not.

error (mandatory)

A mandatory description of the error being thrown.

package (optional, automagic)

Which package the exception was thrown in. Will be filled in automagically if not specified. This is currently not used for generating the error message but caller provides this so we store it.

filename (optional, automagic)

Which filename the code we throw in belongs to. Will as with package be filled in automagically if nothing is provided.

line (optional, automagic)

Which line we threw the exception at. Also automagic.

METHODS

throw

Throws an exception. It will collect information about the caller and fill in the attributes with this unless they are provided by the user. Then the exception object is created

rethrow

Rethrow throws an existing object. It will unlike throw not attempt to collect any information about the caller even if none currently is set.

new

Simply creates the object. Does not collect any information about the environment, nor does it cause the exception to be thrown.

stringify

Generates a string representation of the exception, similar to an ordinary die() message. The stringification overload calls this method to generate an error, so override this if you want to change that.

CAVEATS

My philosophy is that once an exception is thrown, you're no longer interested in performance as top priority. This module uses Moose beneath the hood, which is a slightly heavy module. This may change in the future, but will in any case not affect you when no exceptions are thrown.

SEE ALSO

Exception::Class
Moose

BUGS

Most software has bugs. This module probably isn't an exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR

Anders Nor Berle <debolaz@gmail.com>

COPYRIGHT AND LICENSE

Copyright 2007 by Anders Nor Berle.

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