Name

File::DataClass::Exception - Exception class composed from traits

Synopsis

use File::DataClass::Functions qw( throw );
use Try::Tiny;

sub some_method {
   my $self = shift;

   try   { this_will_fail }
   catch { throw $_ };
}

# OR
use File::DataClass::Exception;

sub some_method {
   my $self = shift;

   eval { this_will_fail };
   File::DataClass::Exception->throw_on_error;
}

# THEN
try   { $self->some_method() }
catch { warn $_."\n\n".$_->stacktrace."\n" };

Description

An exception class that supports error messages with placeholders, a "throw" in File::DataClass::Exception::TraitFor::Throwing method with automatic re-throw upon detection of self, conditional throw if an exception was caught and a simplified stacktrace

Applies exception roles to the exception base class Unexpected. See "Dependencies" for the list of roles that are applied

Error objects are overloaded to stringify to the full error message plus a leader if the optional ErrorLeader role has been applied

Configuration and Environment

Ignores File::DataClass::IO when creating exception leaders

Defines these attributes;

out

A string containing the output from whatever was being called before it threw

Subroutines/Methods

BUILDARGS

Doesn't modify the BUILDARGS method. This is here to workaround a bug in Moo and / or Test::Pod::Coverage

as_string

$printable_string = $e->as_string

What an instance of this class stringifies to

caught

$e = File::DataClass::Exception->caught( $error );

Catches and returns a thrown exception or generates a new exception if EVAL_ERROR has been set or if an error string was passed in

clone

$clone = $e->clone;

Returns a clone of the exception object

stacktrace

$lines = $e->stacktrace( $num_lines_to_skip );

Return the stack trace. Defaults to skipping zero lines of output Skips anonymous stack frames, minimalist

throw

File::DataClass::Exception->throw( $error );

Create (or re-throw) an exception to be caught by the "caught" method. If the passed parameter is a reference it is re-thrown. If a single scalar is passed it is taken to be an error message code, a new exception is created with all other parameters taking their default values. If more than one parameter is passed the it is treated as a list and used to instantiate the new exception. The error attribute must be provided in this case

throw_on_error

File::DataClass::Exception->throw_on_error( $error );

Calls "caught" and if the was an exception "throw"s it

Diagnostics

None

Dependencies

namespace::autoclean
Moo
Unexpected

Incompatibilities

There are no known incompatibilities in this module

Bugs and Limitations

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Acknowledgements

Larry Wall - For the Perl programming language

Throwable::Error - Lifted the stack frame filter from here

Author

Peter Flanigan, <pjfl@cpan.org>

License and Copyright

Copyright (c) 2017 Peter Flanigan. All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic

This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE