[dancer-users] D1 throwing strings, not always Dancer::Exceptions

Warren Young warren at etr-usa.com
Tue Oct 17 02:38:34 BST 2017

I just needed to hook on_handler_exception in a D1 app for the first time, and was surprised to find that it doesn’t obey [the docs][1]:

hook on_handler_exception => sub {
    # The docs say we're passed a Dancer::Exception object, but that is
    # not true: we are sometimes passed a plain string!
    my $exception = shift;
    my $msg = ref($exception) ? $exception->message() : "STR[$exception]";

Simple test case: drop this into a route while Perl strict mode is enabled:

    debug 'This will throw an error ' . undef;

You will get the STR[message] form above.

[1]: https://metacpan.org/pod/Dancer#hook

More information about the dancer-users mailing list