ObjectException.pm

Code Index:


#
# 	sebastien.letort@toulouse.inra.fr
#	Created: May 09, 2007
#	Last Updated: september 20, 2007
#

package LipmError::ObjectException;


NAME

        LipmError::ObjectException - a class to define specific exception of Objects


SYNOPSIS

        throw LipmError::ObjectException( $class_name, KEYWORD, -text => $msg );
        throw LipmError::ObjectException( $obj, KEYWORD, -text => $msg );
        catch LipmError::ObjectException with {...}


DESCRIPTION

        With this class you can describe all type of exception encountered by object.
        - try to access to an attribute that doesn't exist
        - an attribute doesn't have a correct value


AUTHOR

Sebastien Letort : sebastien.letort@toulouse.inra.fr

use warnings;
use strict;

## this class inherit from LipmError.pm
use base qw(LipmError);

BEGIN
{
    our $VERSION = do {my @r = (q$Rev$ =~ /\d+/g); $r[0]};
}

use constant CAN_T_BE_INSTANCIED => 1;
use constant UNKNOWN             => 9;

Object new

 Title        : new
 Usage        : my $o_err = new LipmError::ObjectException( $obj|$class_name, KEYWORD, -text => $msg);
 Prerequisite : it's better for an error to be catch !
 Object       : Constructor, initialize the object
 Returns      : the object.
 Args         : none
 Globals      : none
sub new
{
    my $class = shift;
    my ($arg_un, $keyword) = (shift, shift);
    my %h_param = (@_);

    local $Error::Depth = $Error::Depth + 1;

    # 	local $Error::Debug = 1;  # Enables storing of stacktrace

    my $tmp = ref($arg_un);
    my ($class_obj, $obj) = ($tmp eq '') ? ($arg_un, undef) : ($tmp, $arg_un);

    my $o_err = $class->SUPER::new(
        -object => $obj,
        -class  => $class_obj,

        # 									-text => $text,
        %h_param
        );

    return $o_err;
}

sub Explain
{
    my $self = shift;

    # Construct message
    my $msg = $self->GetMsg() . $self->text();

    return $msg;
}

1;