develooper Front page | perl.perl5.porters | Postings from October 2016

Exception::Class & Try::Tiny

Thread Next
October 2, 2016 21:48
Exception::Class & Try::Tiny
Message ID:
Hi! I'm looking at Exception::Class documentation and it recommends to 
use Try::Tiny module (for non Moose code).

But problem with Try::Tiny is that in catch block caller needs to always 
check if cough exception is really blessed object from package 
Exception::Class::Base. So to correctly handle exception, something like 
this needs to be used for every try { ... } catch { ... } usage.

try { ... } catch {
	if ( blessed $_ && $_->isa('Exception::Class::Base') ) {
	} else {

I found on cpan module Exception::Class::TryCatch which automatically 
create Exception::Class::Base object from any non-object exception, but 
with this module caller must use eval yourself and correctly. How to use 
eval correctly is written in Try::Tiny BACKGROUND documentation:

So.. what do you think would be useful for more people cpan module which

1) will use Tiny::Try

2) and if exception is not Exception::Class::Base object then
   automatically create it (like Exception::Class::TryCatch)


Expected usage:

try {
} catch {
	# $_ is always Exception::Class::Base or derived
	process($_) if $_->isa('My::Exception');

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About