Peter de Vos > BPM-Engine > BPM::Engine::Exceptions

Download:
BPM-Engine-0.01.tar.gz

Dependencies

Annotate this POD

Website

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.01   Source  

NAME ^

BPM::Engine::Exceptions - Exception classes used in BPM::Engine

VERSION ^

0.01

SYNOPSIS ^

Throw an exception when something is wrong

    use BPM::Engine::Exceptions qw/throw_plugin/;

    sub set_length {
        my ($self, $length) = @_;

        # throw an exception
        throw_plugin("Whoops!") unless $length =~ /\d+/;

        # ...
        }    

Now let's try something illegal and catch the exception

    # use the is_Exception() function exported from the types library
    use BPM::Engine::Types qw/Exception/;    
    
    eval {
        $obj->set_length( 'non-numerical value' ); # this throws the error
        #...
    };
    
    # handle any exception, cathing them in various ways
    if(my $err = $@) {
        # encountered an error
        
        if( Exception::Class->caught('BPM::Engine::Exception::Engine') ) {
            #... use the thrown error obj
            warn $err->error;
            print $err->as_html;
            }
        elsif(my $err = BPM::Engine::Exception::Plugin->caught() ) {
            warn $err->trace->as_string;
            }
        # the type tests blessed $@ && $@->isa('BPM::Engine::Exception')
        elsif( is_Exception($err) ) {
            $err->rethrow();
            }
        else {
            # something bad happened!
            die $@;
            }
        }

BPM::Engine::Exception stringifies to something reasonable, so if you don't need detailed error information, you can simply treat $@ as a string:

    eval { $engine->update($status) };
    if ( $@ ) {
        warn "update failed because: $@\n";
    }

DESCRIPTION ^

This module creates the hierarchy of exception objects used by other BPM::Engine modules and provides shortcuts to make raising an exception easier and more readable.

The exceptions are subclasses of Exception::Class::Base, created by the interface defined by Exception::Class. See Exception::Class for more information on how this is done.

EXCEPTIONS ^

Each of the exception classes created by BPM::Engine::Exceptions has a functional alias for its throw class method. In the SYNOPSIS example, we use the throw_plugin function to throw a BPM::Engine::Exception::Plugin exception.

These may be imported by passing a list of the function names to import:

  use BPM::Engine::Exceptions qw(throw_component);

Some of the exceptions mentioned above have additional fields, which are available via accessors.

The exception classes created by BPM::Engine::Exceptions are as follows:

DEPENDENCIES ^

AUTHOR ^

Peter de Vos <sitetech@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (c) 2010, 2011 Peter de Vos <sitetech@cpan.org>.

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

syntax highlighting: