'eval' 块捕获 'die' 尝试。但在下面的代码中,它未能捕获“未初始化值”异常。
perl 代码 -
#!/usr/bin/perl
package poc::template;
use strict;
use warnings;
use Log::Log4perl;
my $log_conf = "../conf/log4perl.conf";
Log::Log4perl::init($log_conf);
my $logger = Log::Log4perl->get_logger();
sub doSome {
$logger->info('doing something');
my $add = $ARGV[0] + 4;
}
#main
$logger->info('start');
eval { doSome(); };
if ($@) {
$logger->info('error');
}
$logger->info('stop');
这是日志配置-
log4perl.rootLogger = DEBUG, SCREEN
log4perl.appender.SCREEN = Log::Log4perl::Appender::Screen
log4perl.appender.SCREEN.stderr = 0
log4perl.appender.SCREEN.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.SCREEN.layout.ConversionPattern = %d [%M:%L] %p %F{2} - %m%n
这是脚本输出 -
2013/02/03 16:47:02 [main:::18] INFO template\POCTemplate.pl - start
Use of uninitialized value $ARGV[0] in addition (+) at /POCPerl/template/POCTemplate.pl line 14.
2013/02/03 16:47:02 [poc::template::doSome:13] INFO template\POCTemplate.pl - doing something
2013/02/03 16:47:02 [main:::23] INFO template\POCTemplate.pl - stop
这个 eval 块不应该捕获那个异常吗?