Bot::Cobalt::Error - Lightweight error objects
package SomePackage; sub some_method { . . . die Bot::Cobalt::Error->new( "Some errors occured:", @errors )->join("\n"); ## ... same as: die Bot::Cobalt::Error->new( "Some errors occured:\n", join("\n", @errors) ); } package CallerPackage; use Try::Tiny; try { SomePackage->some_method(); } catch { ## $error isa Bot::Cobalt::Error my $error = $_; ## Stringifies to the error string: warn "$error\n"; };
A lightweight exception object for Bot::Cobalt.
new() takes a list of messages used to compose an error string.
The objects themselves stringify to the concatenated stored errors.
A Devel::StackTrace instance is created at construction time; it is accessible via "trace".
Returns the current error string; this is the same value returned when the object is stringified, such as:
warn "$error\n";
$error = $error->join("\n");
Returns a new object whose only element is the result of joining the stored list of errors with the specified expression.
Defaults to joining with a single space. Does not modify the existing object.
$error = $error->push(@errors);
Appends the specified list to the existing array of errors.
Modifies and returns the existing object.
$error = $error->slice(0 .. 2);
Returns a new object whose elements are as specified. Does not modify the existing object.
my $err = Bot::Cobalt::Error->new; $err->push( @errors ); $err->throw
Throw an exception by calling die() with the current object. The Devel::StackTrace object is reinstanced from where throw() is called (see "trace").
## Stack trace as string: warn $error->trace->as_string;
A Devel::StackTrace instance; see Devel::StackTrace.
$error = $error->unshift(@errors);
Prepends the specified list to the existing array of errors.
Jon Portnoy <avenj@cobaltirc.org>
To install Bot::Cobalt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bot::Cobalt
CPAN shell
perl -MCPAN -e shell install Bot::Cobalt
For more information on module installation, please visit the detailed CPAN module installation guide.