NAME

Venus::Error - Error Class

ABSTRACT

Error Class for Perl 5

SYNOPSIS

package main;

use Venus::Error;

my $error = Venus::Error->new;

# $error->throw;

DESCRIPTION

This package represents a context-aware error (exception object).

ATTRIBUTES

This package has the following attributes:

context

context(Str)

This attribute is read-write, accepts (Str) values, is optional, and defaults to '(None)'.

message

message(Str)

This attribute is read-write, accepts (Str) values, is optional, and defaults to 'Exception!'.

INHERITS

This package inherits behaviors from:

Venus::Kind::Utility

INTEGRATES

This package integrates behaviors from:

Venus::Role::Explainable

Venus::Role::Stashable

METHODS

This package provides the following methods:

explain

explain() (Str)

The explain method returns the error message and is used in stringification operations.

Since 0.01

explain example 1
# given: synopsis;

my $explain = $error->explain;

# "Exception! in ...

frames

frames() (ArrayRef)

The frames method returns the compiled and stashed stack trace data.

Since 0.01

frames example 1
# given: synopsis;

my $frames = $error->frames;

# [
#   ...
#   [
#     "main",
#     "t/Venus_Error.t",
#     ...
#   ],
# ]

throw

throw(Any @data) (Error)

The throw method throws an error if the invocant is an object, or creates an error object using the arguments provided and throws the created object.

Since 0.01

throw example 1
# given: synopsis;

my $throw = $error->throw;

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

trace

trace(Int $offset, Int $limit) (Error)

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

Since 0.01

trace example 1
# given: synopsis;

my $trace = $error->trace;

# bless({ ... }, 'Venus::Error')
trace example 2
# given: synopsis;

my $trace = $error->trace(0, 1);

# bless({ ... }, 'Venus::Error')
trace example 3
# given: synopsis;

my $trace = $error->trace(0, 2);

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

OPERATORS

This package overloads the following operators:

operation: (.)

This package overloads the . operator.

example 1

# given: synopsis;

my $string = $error . ' Unknown';

# "Exception! Unknown"
operation: (eq)

This package overloads the eq operator.

example 1

# given: synopsis;

my $result = $error eq 'Exception!';

# 1
operation: (ne)

This package overloads the ne operator.

example 1

# given: synopsis;

my $result = $error ne 'exception!';

# 1
operation: (qr)

This package overloads the qr operator.

example 1

# given: synopsis;

my $test = 'Exception!' =~ qr/$error/;

# 1

AUTHORS

Cpanery, cpanery@cpan.org

LICENSE

Copyright (C) 2021, Cpanery

Read the "license" file.