The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Object::Exception - Multi-threaded exception class

VERSION

version 1.14

ABSTRACT

Multi-threaded exception class

        package SampleException;
        use Object::Base qw(Object::Exception);
        #
        package main;
        use Object::Exception;
        #
        # Enable DEBUG for traceback
        our $DEBUG = 1;
        #
        # throws Object::Exception type and its msg: Exception1
        eval
        {
                throw("Exception1");
        };
        if ($@)
        {
                warn $@ if ref($@) eq "Object::Exception";
        }
        #
        # throws SampleException type and its msg: This is sample exception
        sub sub_exception
        {
                SampleException->throw("This is sample exception");
        }
        eval
        {
                sub_exception();
        };
        if ($@) {
                # $@ and $@->message returns same result
                warn $@->message if ref($@) eq "SampleException";
        }
        #
        # throws Object::Exception type and its message: SampleException. Because msg is not defined!
        eval
        {
                SampleException->throw();
        };
        if ($@)
        {
                if (ref($@) eq "SampleException")
                {
                        warn $@;
                } else
                {
                        # warns 'This is type of Object::Exception and its message: SampleException'
                        warn "This is type of ".ref($@)." and its message: $@";
                }
        }

DESCRIPTION

Functions

traceback($level)

returns array specified level of traceback by calling point of traceback function.

dump_trace(@trace)

returns string dump of trace array. Always ends with "\n".

throw($msg)

dies with new Object::Exception instance with specified message.

Methods

$class->new($msg)

returns new Object::Exception instance with specified message. If $main::DEBUG is setted TRUE, $object->debug attribute is setted 1.

$object->message()

returns message of Object::Exception instance. If $msg is defined with new() or throw(), always ends with "\n". If $object->debug attribute is TRUE, dump generated with dump_trace is added to end of message.

$class->throw($msg)

dies with new Object::Exception derived-class instance with specified message. If $class is not derived from Object::Exception, does nothing. $msg value must be specified explicitly and it can be undef. Otherwise, method runs as throw($class) function.

REPOSITORY

GitHub https://github.com/orkunkaraduman/p5-Object-Base

CPAN https://metacpan.org/release/Object-Base

SEE ALSO

AUTHOR

Orkun Karaduman <orkunkaraduman@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2017 Orkun Karaduman <orkunkaraduman@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.