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:

frame

frame(Int)

This attribute is read-write, accepts (Int) values, and is optional.

name

name(Str)

This attribute is read-write, accepts (Str) values, and is optional.

message

message(Str)

This attribute is read-write, accepts (Str) values, and is optional.

package

package(Str)

This attribute is read-only, accepts (Str) values, and is optional.

parent

parent(Str)

This attribute is read-only, accepts (Str) values, is optional, and defaults to 'Venus::Error'.

context

context(Str)

This attribute is read-only, accepts (Str) values, and is optional.

INHERITS

This package inherits behaviors from:

Venus::Kind::Utility

INTEGRATES

This package integrates behaviors from:

Venus::Role::Stashable

METHODS

This package provides the following methods:

as

as(Str $name) (Throw)

The as method sets a "name" for the error and returns the invocant.

Since 2.55

as example 1
# given: synopsis

package main;

$throw = $throw->as('on.handler');

# bless({...}, 'Venus::Throw')

error

error(HashRef $data) (Error)

The error method throws the prepared error object.

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)!',
});

# 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")

on

on(Str $name) (Throw)

The on method sets a "name" for the error in the form of "on.$subroutine.$name" or "on.$name" (if outside of a subroutine) and returns the invocant.

Since 2.55

on example 1
# given: synopsis

package main;

$throw = $throw->on('handler');

# bless({...}, 'Venus::Throw')

# $throw->name;

# "on.handler"
on example 2
# given: synopsis

package main;

sub execute {
  $throw->on('handler');
}

$throw = execute();

# bless({...}, 'Venus::Throw')

# $throw->name;

# "on.execute.handler"

OPERATORS

This package overloads the following operators:

operation: ("")

This package overloads the "" operator.

example 1

# given: synopsis;

my $result = "$throw";

# "Exception!"
operation: (~~)

This package overloads the ~~ operator.

example 1

# given: synopsis;

my $result = $throw ~~ 'Exception!';

# 1

AUTHORS

Awncorp, awncorp@cpan.org

LICENSE

Copyright (C) 2000, Al Newkirk.

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.