Dancer::Error(3pm) User Contributed Perl Documentation Dancer::Error(3pm)NAME
Dancer::Error - class for representing fatal errors
SYNOPSIS
# taken from send_file:
use Dancer::Error;
my $error = Dancer::Error->new(
code => 404,
message => "No such file: `$path'"
);
Dancer::Response->set($error->render);
DESCRIPTION
With Dancer::Error you can throw reasonable-looking errors to the user instead of crashing the application and filling up the logs.
This is usually used in debugging environments, and it's what Dancer uses as well under debugging to catch errors and show them on screen.
ATTRIBUTES
code
The code that caused the error.
This is only an attribute getter, you'll have to set it at "new".
title
The title of the error page.
This is only an attribute getter, you'll have to set it at "new".
message
The message of the error page.
This is only an attribute getter, you'll have to set it at "new".
exception
The exception that caused the error. If the error was not caused by an exception, returns undef. Exceptions are usually objects that
inherits of Dancer::Exception.
This is only an attribute getter, you'll have to set it at "new".
METHODS /SUBROUTINES
new
Create a new Dancer::Error object.
title
The title of the error page.
type
What type of error this is.
code
The code that caused the error.
message
The message that will appear to the user.
exception
The exception that will be useable by the rendering.
backtrace
Create a backtrace of the code where the error is caused.
This method tries to find out where the error appeared according to the actual error message (using the "message" attribute) and tries to
parse it (supporting the regular/default Perl warning or error pattern and the Devel::SimpleTrace output) and then returns an error-
higlighted "message".
tabulate
Small subroutine to help output nicer.
dumper
This uses Data::Dumper to create nice content output with a few predefined options.
render
Renders a response using Dancer::Response.
environment
A main function to render environment information: the caller (using "get_caller"), the settings and environment (using "dumper") and more.
get_caller
Creates a strack trace of callers.
_censor
An internal method that tries to censor out content which should be protected.
"dumper" calls this method to censor things like passwords and such.
_html_encode
Internal method to encode entities that are illegal in (X)HTML. We output as UTF-8, so no need to encode all non-ASCII characters or use a
module. FIXME : this is not true anymore, output can be any charset. Need fixing.
AUTHOR
Alexis Sukrieh
LICENSE AND COPYRIGHT
Copyright 2009-2010 Alexis Sukrieh.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as
published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
perl v5.14.2 2012-03-31 Dancer::Error(3pm)
Check Out this Related Man Page
Dancer::Exception::Base(3pm) User Contributed Perl Documentation Dancer::Exception::Base(3pm)NAME
Dancer::Exception::Base - the base class of all Dancer exceptions
DESCRIPTION
Dancer::Exception::Base is the base class of all Dancer exception. All core exceptions, and all custom exception registered using
"Dancer::Exception::register_exception" inherits of "Dancer::Exception::Base".
METHODS
throw
Throws an exception. It's what "raise" (from Dancer::Exception) uses. Any arguments is set as raising parameters. You should not use this
method directly, but instead, use "raise" from Dancer::Exception.
Warning, if you want to rethrow an exception, use "rethrow".
rethrow
Re-throw the exception, without touching its parameters. Useful if you've caught and exception but don't want to handle it, and want to
rethrow it.
try { ... }
catch {
my ($e) = @_;
$e->does('InvalidLogin')
or $e->rethrow;
...
};
does
Given an exception type, returns true if the exception is of the same type.
try { raise InvalidLogin => 'foo'; }
catch {
my ($e) = @_;
$e->does('InvalidLogin') # true
...
};
It can receive more than one type, useful for composed exception, or checking multiple types at once. "does" performs a logical OR between
them:
try { raise InvalidPassword => 'foo'; }
catch {
my ($e) = @_;
$e->does('InvalidLogin', 'InvalidPassword') # true
...
};
get_composition
Returns the composed types of an exception. As every exception inherits of Dancer::Exception::Base, the returned list contains at least
'Base', and the exception class name.
Warning, the result is a list, so you should call this method in list context.
try { raise InvalidPassword => 'foo'; }
catch {
my ($e) = @_;
my @list = $e->get_composition()
# @list contains ( 'InvalidPassword', 'Base', ... )
};
message
Computes and returns the message associated to the exception. It'll apply the parameters that were set at throw time to the message pattern
of the exception.
STRINGIFICATION
string overloading
All Dancer exceptions properly stringify. When evaluated to a string, they return their message, concatenated with their stack trace (see
below).
cmp overloading
The "cmp" operator is also overloaded, thus all the string operations can be done on Dancer's exceptions, as they will all be based on the
overloaded "cmp" operator. Dancer exceptions wil be compared without their stacktraces.
STACKTRACE
Similarly to Carp, Dancer exceptions stringification appends a string stacktrace to the exception message.
The stacktrace can be a short one, or a long one. Actually the implementation internally uses Carp.
To enable long stack trace (for debugging purpose), you can use the global variable "Dancer::Exception::Verbose" (see below).
The short and long stacktrace snippets are stored within "$self-"{_shortmess}> and "$self-"{_longmess}>. Don't touch them or rely on them,
they are internals, and will change soon.
GLOBAL VARIABLE
$Dancer::Exception::Verbose
When set to 1, exceptions will stringify with a long stack trace. This variable is similar to $Carp::Verbose. I recommend you use it like
that:
local $Dancer::Exception::Verbose;
$Dancer::Exception::Verbose = 1;
All the Carp global variables can also be used to alter the stacktrace generation.
perl v5.14.2 2012-03-31 Dancer::Exception::Base(3pm)