From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

Data::Object::Exception

Exception Class for Perl 5

method: explain method: throw method: trace

id: ro, opt, Str context: ro, opt, Any message: ro, opt, Str

my $exception = Data::Object::Exception->new;
# $exception->throw

This package provides functionality for creating, throwing, and introspecting exception objects.

The package allows objects to be instantiated with a single argument.

my $exception = Data::Object::Exception->new('Oops!');
# $exception->throw

The package allows objects to be instantiated with key-value arguments.

my $exception = Data::Object::Exception->new(message => 'Oops!');
# $exception->throw

The throw method throws an error with message (and optionally, an ID).

throw(Tuple[Str, Str] | Str $message, Any $context, Maybe[Number] $offset) : Any

=example-1 throw

my $exception = Data::Object::Exception->new;
$exception->throw('Oops!')

=example-2 throw

my $exception = Data::Object::Exception->new('Oops!');
$exception->throw

=example-3 throw

my $exception = Data::Object::Exception->new;
$exception->throw(['E001', 'Oops!'])

The explain method returns an error message with stack trace.

explain() : Str

=example-1 explain

my $exception = Data::Object::Exception->new('Oops!');
$exception->explain

The trace method compiles a stack trace and returns the object. By default it skips the first frame.

trace(Int $offset, $Int $limit) : Object

=example-1 trace

my $exception = Data::Object::Exception->new('Oops!');
$exception->trace(0)

=example-2 trace

my $exception = Data::Object::Exception->new('Oops!');
$exception->trace(1)

=example-3 trace

my $exception = Data::Object::Exception->new('Oops!');
$exception->trace(0,1)

16 POD Errors

The following errors were encountered while parsing the POD:

Around line 10:

Unknown directive: =name

Around line 16:

Unknown directive: =abstract

Around line 22:

Unknown directive: =includes

Around line 30:

Unknown directive: =attributes

Around line 38:

Unknown directive: =synopsis

Around line 48:

Unknown directive: =description

Around line 55:

Unknown directive: =scenario

Around line 59:

Unknown directive: =example

Around line 69:

Unknown directive: =scenario

Around line 73:

Unknown directive: =example

Around line 83:

Unknown directive: =method

Around line 87:

Unknown directive: =signature

Around line 117:

Unknown directive: =method

Around line 121:

Unknown directive: =signature

Around line 135:

Unknown directive: =method

Around line 140:

Unknown directive: =signature