NAME
Venus::Throw - Throw Class
ABSTRACT
Throw Class for Perl 5
SYNOPSIS
package main;
use Venus::Throw;
my $throw = Venus::Throw->new;
# $throw->error;
DESCRIPTION
This package provides a mechanism for generating and raising errors (exception objects).
ATTRIBUTES
This package has the following attributes:
package
package(string $package) (string)
The package attribute is read-write, accepts (string) values, and is optional.
Since 4.15
- package example 1
-
# given: synopsis package main; my $package = $throw->package("Example"); # "Example"
- package example 2
-
# given: synopsis # given: example-1 package package main; $package = $throw->package; # "Example"
parent
parent(string $parent) (string)
The parent attribute is read-write, accepts (string) values, and is optional.
Since 4.15
- parent example 1
-
# given: synopsis package main; my $parent = $throw->parent("Venus::Error"); # "Venus::Error"
- parent example 2
-
# given: synopsis # given: example-1 parent package main; $parent = $throw->parent; # "Venus::Error"
INHERITS
This package inherits behaviors from:
METHODS
This package provides the following methods:
die
die(hashref $data) (Venus::Error)
The die method builds an error object from the attributes set on the invocant and throws it.
Since 4.15
- die example 1
-
# given: synopsis; my $die = $throw->die; # bless({ # ..., # "context" => "(eval)", # "message" => "Exception!", # }, "Main::Error")
- die example 2
-
# given: synopsis; my $die = $throw->die({ message => 'Something failed!', context => 'Test.error', }); # bless({ # ..., # "context" => "Test.error", # "message" => "Something failed!", # }, "Main::Error")
- die example 3
-
package main; use Venus::Throw; my $throw = Venus::Throw->new('Example::Error'); my $die = $throw->die; # bless({ # ..., # "context" => "(eval)", # "message" => "Exception!", # }, "Example::Error")
- die example 4
-
package main; use Venus::Throw; my $throw = Venus::Throw->new( package => 'Example::Error', parent => 'Venus::Error', ); my $die = $throw->die({ message => 'Example error!', }); # bless({ # ..., # "context" => "(eval)", # "message" => "Example error!", # }, "Example::Error")
- die example 5
-
package Example::Error; use base 'Venus::Error'; package main; use Venus::Throw; my $throw = Venus::Throw->new( package => 'Example::Error::Unknown', parent => 'Example::Error', ); my $die = $throw->die({ message => 'Example error (unknown)!', }); # bless({ # ..., # "context" => "(eval)", # "message" => "Example error (unknown)!", # }, "Example::Error::Unknown")
- die example 6
-
package main; use Venus::Throw; my $throw = Venus::Throw->new( package => 'Example::Error::NoThing', parent => 'No::Thing', ); my $die = $throw->die({ message => 'Example error (no thing)!', raise => true, }); # No::Thing does not exist # Exception! Venus::Throw::Error (isa Venus::Error)
- die example 7
-
# given: synopsis; my $die = $throw->die({ name => 'on.test.error', context => 'Test.error', message => 'Something failed!', }); # bless({ # ..., # "context" => "Test.error", # "message" => "Something failed!", # "name" => "on_test_error", # }, "Main::Error")
error
error(hashref $data) (Venus::Error)
The error method builds an error object from the attributes set on the invocant and returns or optionally automatically throws it.
Since 0.01
- error example 1
-
# given: synopsis; my $error = $throw->error; # bless({ # ..., # "context" => "(eval)", # "message" => "Exception!", # }, "Main::Error")
- error example 2
-
# given: synopsis; my $error = $throw->error({ message => 'Something failed!', context => 'Test.error', }); # bless({ # ..., # "context" => "Test.error", # "message" => "Something failed!", # }, "Main::Error")
- error example 3
-
package main; use Venus::Throw; my $throw = Venus::Throw->new('Example::Error'); my $error = $throw->error; # bless({ # ..., # "context" => "(eval)", # "message" => "Exception!", # }, "Example::Error")
- error example 4
-
package main; use Venus::Throw; my $throw = Venus::Throw->new( package => 'Example::Error', parent => 'Venus::Error', ); my $error = $throw->error({ message => 'Example error!', }); # bless({ # ..., # "context" => "(eval)", # "message" => "Example error!", # }, "Example::Error")
- error example 5
-
package Example::Error; use base 'Venus::Error'; package main; use Venus::Throw; my $throw = Venus::Throw->new( package => 'Example::Error::Unknown', parent => 'Example::Error', ); my $error = $throw->error({ message => 'Example error (unknown)!', }); # bless({ # ..., # "context" => "(eval)", # "message" => "Example error (unknown)!", # }, "Example::Error::Unknown")
- error example 6
-
package main; use Venus::Throw; my $throw = Venus::Throw->new( package => 'Example::Error::NoThing', parent => 'No::Thing', ); my $error = $throw->error({ message => 'Example error (no thing)!', raise => true, }); # No::Thing does not exist # Exception! Venus::Throw::Error (isa Venus::Error)
- error example 7
-
# given: synopsis; my $error = $throw->error({ name => 'on.test.error', context => 'Test.error', message => 'Something failed!', }); # bless({ # ..., # "context" => "Test.error", # "message" => "Something failed!", # "name" => "on_test_error", # }, "Main::Error")
new
new(any @args) (Venus::Throw)
The new method constructs an instance of the package.
Since 4.15
- new example 1
-
package main; use Venus::Throw; my $new = Venus::Throw->new; # bless(..., "Venus::Throw")
- new example 2
-
package main; use Venus::Throw; my $new = Venus::Throw->new(package => 'Example::Error', parent => 'Venus::Error'); # bless(..., "Venus::Throw")
AUTHORS
Awncorp, awncorp@cpan.org
LICENSE
Copyright (C) 2022, Awncorp, awncorp@cpan.org.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.