|
From: Mike S. <m...@pe...> - 2006-12-04 23:53:02
|
On Mon, 4 Dec 2006, J. David Blackstone wrote:
> I'm trying to do a minimal setup of Log::Log4perl for an
> existing application. I've setup my __WARN__ and __DIE__
> signal handlers to wrap warn() and die(), but I'm running
> into a problem. A portion of my code expects to do the
> following:
>
> eval { ... };
> if ($@)
> {
> return if $@ =~ m/particular error to ignore/;
> die $@;
> }
When you say you've setup your __WARN__ and __DIE__ handlers, I assume
you've set them up according to
http://log4perl.sourceforge.net/d/Log/Log4perl/FAQ.html#73200
in order to have Log4perl catch and log these events.
> In other words, I execute a piece of code that I expect may
> throw a particular type of exception. If that exception
> occurs, I don't want to hear about it. I just want to ignore
> it and go on to the next step. However, if and only if some
> other situation occurs, I want the code to die.
>
> The problem is that now that __WARN__ and __DIE__ are
> wrapped, the exception that I wanted to ignore is now getting
> logged. I don't want that. I want it to be completely silent.
> (Failing that, I'd like to log it at a very low level.)
Hmm, but if you want it to be completely silent, why aren't you simply
resetting those handlers and then putting them back in place afterwards?
eval {
local $SIG{__WARN__} = 'IGNORE';
local $SIG{__DIE__} = 'IGNORE';
# ... your code
};
should automatically reset them after the eval block has been processed.
Alternatively, you could check if you're inside an eval{} (at some
sublevel) by using code like
sub burried_in_eval {
my $i;
while(my ($pack, $file, $line, $sub) = caller($i++)) {
return 1 if $sub eq "(eval)";
}
return 0;
}
and act accordingly in your sig handlers.
-- Mike
Mike Schilli
m...@pe...
>
> jdb
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> log4perl-devel mailing list
> log...@li...
> https://lists.sourceforge.net/lists/listinfo/log4perl-devel
>
|