Maciej Walezak wrote on 6/8/2004, 6:58 AM:
> You can see that the $@ variable is empty. It happens if the get_logger
> subroutine is called from the DESTROY method when an objects is going
> out
> of scope. No DESTROY or no get_logger and the program works fine. I am
> very curious what is wrong here.
I don't think this is related to Log4perl. You can reproduce the same
effect using
sub DESTROY {
#get_logger;
$@ = undef;
}
If you run code in DESTROY (which gets triggered while leaving the eval
{ } block because your object goes out of scope) that's resetting $@,
you'll get this weird behaviour. If you still want this code to be
called, just localize $@:
sub DESTROY {
#get_logger;
local $@;
$@ = undef;
}
--
-- Mike
Mike Schilli
m...@pe...
> Hello Log4Perl team!
>
> I have experienced this problem since version 0.32 of Log4Perl. The
> effect
> is exactly the same on Linux, AIX or Windows with Perl 5.6 or Perl 5.8
> so
> I will not give exact platform specification.
> Run this code to reproduce the problem:
>
> #!/usr/bin/perl
>
> package Base;
> use Log::Log4perl qw(get_logger);
> sub new {
> return bless {}, shift;
> }
> sub DESTROY {
> get_logger;
> }
> 1;
>
> eval {
> my $b = Base->new;
> die "this is the exception";
> };
>
> if ($@) {
> print "Caught exception: >$@<\n";
> } else {
> print "No exception\n";
> }
>
> You can see that the $@ variable is empty. It happens if the get_logger
> subroutine is called from the DESTROY method when an objects is going
> out
> of scope. No DESTROY or no get_logger and the program works fine. I am
> very curious what is wrong here.
>
> Please reply to my private mailbox too as I do not subscribe to this
> list.
> --
> Maciej Walezak
|