[Dancer-users] exception handling

Taric Mirza taric at bigchampagne.com
Wed Mar 9 16:43:38 CET 2011


I want to add some custom exception handling code to a dancer (loving it
so far!) app and am experimenting around.

eg:

use Dancer ':syntax';
use Try::Tiny;

get '/' => sub {
    try {
        my $data = process_data(); # throws Exception::Class objects

        template 'index', {
            'data' => $data,
        };
    }
    catch {
        my $exception = $_;

        template 'error', {
            'exception' => $exception,
        };
    };

    return 1;
};

1;


This works, but I will have to duplicate the exception handling code for
every route.  If "get" and the other route handlers were normal methods,
I would be able to subclass Dancer and add the exception handling code
that way.  But since it is some kind of syntactic sugar, not sure if
that is easily doable.  Any ideas?

Thanks.

--
Taric




More information about the Dancer-users mailing list