1 package Throwable::Error;
3 with 'Throwable', 'StackTrace::Auto';
4 # ABSTRACT: an easy-to-use class for error objects
10 extends 'Throwable::Error';
12 has execution_phase => (
14 isa => 'MyApp::Phase',
20 MyApp::Error->throw("all communications offline");
25 message => "all communications offline",
31 Throwable::Error is a base class for exceptions that will be thrown to signal
32 errors and abort normal program flow. Throwable::Error is an alternative to
33 L<Exception::Class|Exception::Class>, the features of which are largely
34 provided by the Moose object system atop which Throwable::Error is built.
36 Throwable::Error performs the L<Throwable|Throwable> and L<StackTrace::Auto>
37 roles. That means you can call C<throw> on it to create and throw n error
38 object in one call, and that every error object will have a stack trace for its
49 This attribute must be defined and must contain a string describing the error
50 condition. This string will be printed at the top of the stack trace when the
63 This attribute, provided by L<StackTrace::Auto>, will contain a stack trace
64 object guaranteed to respond to the C<as_string> method. For more information
65 about the stack trace and associated behavior, consult the L<StackTrace::Auto>
70 This method will provide a string representing the error, containing the
71 error's message followed by the its stack trace.
78 my $str = $self->message;
79 $str .= "\n\n" . $self->stack_trace->as_string;
85 my ($self, @args) = @_;
87 return {} unless @args;
88 return {} if @args == 1 and ! defined $args[0];
90 if (@args == 1 and (!ref $args[0]) and defined $args[0] and length $args[0]) {
91 return { message => $args[0] };
94 return $self->SUPER::BUILDARGS(@args);
97 __PACKAGE__->meta->make_immutable(inline_constructor => 0);