[Catalyst] Custom error handling

Jonathan Rockway jon at jrock.us
Sat Dec 15 01:04:59 GMT 2007


On Fri, 2007-12-14 at 20:10 +0300, Dmitriy S. Sinyavskiy wrote
> 
> 
> Ok it looks good. I have another question - can I detect error by type
> for example, 
> 
> I need custom error handling only for database error.

Yes, you can die with a ref and then $@ becomes that ref:

   eval {
       my $some_ref = <your exception class>->new;
       die $some_ref;
   };
   if(blessed $@ && $@->isa('<your exception class>'){
      # handle whatever
   }
   elsif ...

Catalyst has Catalyst::Exception and DBIx::Class uses
DBIx::Class::Exception for its errors.  

There are a number of CPAN modules that can make this sort of exception
handling easier.  Error is one of them, but I don't know what's
recommended these days.

Regards,
Jonathan Rockway

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20071214/3d10225b/attachment-0001.pgp


More information about the Catalyst mailing list