sourCEntral - mobile manpages




Dancer::Exception::Base − the base class of all Dancer exceptions


version 1.3140


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".


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".

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) = @_;
      or $e−>rethrow;

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

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', ... )

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.


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 will be compared without their stacktraces.


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.


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.


Dancer Core Developers


This software is copyright (c) 2010 by Alexis Sukrieh.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.