Object-InsideOut - Re: Problematic use of signal __DIE__ handlers in OIO internals

Posted on Fri Sep 12 20:00:31 2008 by jdhedden in response to 8796 (See the whole thread of 3)
Re: Problematic use of signal __DIE__ handlers in OIO internals
One of design philosophies of OIO was to use an object-oriented approach to error handling as suggested in Damian Conway's book "Perl Best Practices." By using Exception::Class for this, OIO is meant to work with custom exception handling.

The need for "local $SIG{'__DIE__'};" statements inside :Init, etc. subroutines is documented in the POD, but not specifically for purpose you outlined. I'll try to expand on this for the next release. Thanks.

In your example, aside from adding "local $SIG{'__DIE__'};" to the 'eval' in _init(), if you create your own Exception::Class objects, you can generate the type of behavior I think you're looking for:
#!/usr/bin/perl use strict; use warnings; package A; { use Object::InsideOut; sub _init :Init { eval { local $SIG{'__DIE__'}; B::foo(); }; main::custom_throw() if $@; } } package B; { use Carp qw(croak); sub foo { croak "Threw an error for fun" }; } package main; use Exception::Class ( 'MyBad' => { 'description' => 'Minimalist exception class', }, ); sub custom_throw { MyBad->throw( 'message' => "I'd like to throw some perl error as is, " . "rather than one with OIO debug-info clutter: $@", ); } A->new();
Hope that helps.
Direct Responses: 8800 | Write a response