telcontar has asked for the wisdom of the Perl Monks concerning the following question:
A bit of testing has shown that when eval is used in the destructor of package "Testing", the eval in package "main" does not work, e.g. a croak thrown in a sub inside that eval does not seem to call die(). But why?#!/usr/bin/perl package Testing; use HTML::TreeBuilder; sub new { my $class = $_[0]; $class = ref($class) || $class; my $self = { tree => HTML::TreeBuilder->new() }; bless $self, $class } sub DESTROY { my $self = shift; eval { $self->{tree} = $self->{tree}->delete(); }; } sub do_something { Carp::croak "DIE! DIE! DIE!" } package main; eval { my $page = Testing->new(); $page->do_something(); }; if ($@) { print STDERR "Error: " . $@ if $@; exit 1; } exit 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: croak() does not "die" when DESTROY is used
by codeacrobat (Chaplain) on Aug 07, 2007 at 06:40 UTC | |
|
Re: croak() does not "die" when DESTROY is used
by ysth (Canon) on Aug 07, 2007 at 06:27 UTC | |
|
Re: croak() does not "die" when DESTROY is used
by ikegami (Patriarch) on Aug 07, 2007 at 14:30 UTC |