Exception handling

32 views
Skip to first unread message

Stanislav Blinov

unread,
Apr 6, 2014, 9:42:43 AM4/6/14
to mojol...@googlegroups.com
Hi,

I am trying to catch exception that raises when Mojo::DOM cannot find
anything at specified location.

For example, when I run:
$content = $dom->at('html body div#ja-contents > table + table > tr > td') ;

I am getting exception page with following error: [...]Can't call
method "find" on an undefined value at
script/../lib/Cms/Admin.pm line 934.[...]

When I am trying:

eval {
$content = $dom->at('html body div#ja-contents > table + table > tr > td') ;
}
or do {
$self->render(text => Dumper($@));
return;
};

The string is just empty.
Is there is anyway to render as text only error message that I am
getting without eval?

Sergey Dmitriev

unread,
Apr 7, 2014, 5:26:55 AM4/7/14
to mojol...@googlegroups.com
Have you tried Try::Tiny?

try {
...
} catch {
  say "error: $_";
};

HtH, Sergey Dmitriev
"All that is necessary for evil to triumph is for good men to do nothing". -- Edmund Burke



--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Stanislav Blinov

unread,
Apr 8, 2014, 3:06:25 AM4/8/14
to mojol...@googlegroups.com
Yes, it doesn't works at all.
Reply all
Reply to author
Forward
0 new messages