in reply to Trapping errors with specificity

You can die with an object as well. CPAN has a number of modules for creating exception classes. Error provides Java-type syntax (try/catch), but I prefer the more Perlish Exception::Class.

Update: So in your example, you could do something like:

eval { $code_ref->(); }; if ( my $e = $@ ) { if( UNIVERSAL::isa($e, 'Exception::Class') { # handle exception here } else { # parse string from die } }

Replies are listed 'Best First'.
Re^2: Trapping errors with specificity
by diotalevi (Canon) on Aug 07, 2006 at 19:10 UTC

    I believe you have missed the point. I'm looking at your "parse string from die" branch. Exception objects should be entirely ignorable as a problem space because it's already solved. If I throw them I can identify them and if someone else throws them I can identify them as not being mine. It's when I just get a string that I have to decide "thrown from this file and four lines up?"

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊