"Joshua ben Jore" schreef: > Dr.Ruud: >> Joshua ben Jore: >>> Semi-recently at work I found that a few buggy exception objects in >>> the global $@ were clearing themselves out of $@ as a side effect of >>> examining them for truth. >> >> Oops, I'd better change my >> >> push @errors, $@ if $@; >> >> to something like >> >> {my $e; push @errors, $e if $e = $@} > > No, that's only if you have exception objects which might also have > overloading. This was about any kind, so including those. > Also, you can only trust $@ as long as you also trust > that you'll never have objects around that can clear $@ during their > DESTROY phase. The presence of objects which can set $@ during their > DESTROY means your evail{} can fail and $@ can be empty afterwards. > It's why you have to actually return something from eval or assign > success out somewhere. > > For "95%" of perl code, trusting that $@ is an ok boolean works. For > the other 5%, set phasers to kill and raise all shields. > > my $ok = eval { ...; return 1}; > unless( $ok ) { > my $e = $@; > ... > } I tend to write that as an "or": eval { ... 1; } or { my $e = $@; printf LOG "[%s] %s\n", scalar localtime, $e; }; which could also look more like { my @errors; push @errors, $@ if $@; eval { push @errors, $@ if $@; ... 1; } or { push @errors, $@; }; die @errors if @errors; } -- Affijn, Ruud "Gewoon is een tijger."Thread Previous | Thread Next