[EDIT] - with the benefit of hindsight, this question was misdirected. I have not deleted it because it is a good example of the incorrect use of eval and correct criticism by Perl::Critic.
Perl Critic raises the following criticism for the code below:
Return value of eval not tested. You can't depend upon the value of
$@/$EVAL_ERROR
to tell whether an eval failed
my $Jet = Win32::OLE->CreateObject('DAO.DBEngine.36')
or croak "Can't create Jet database engine.";
my $DB = $Jet->OpenDatabase($DBFile)
# code omitted for the sake of brevity
# perl script writes results to Access db via an append query
$DB->Execute( $SQLquery, 128 ); #128=DBFailOnError
eval {$err = Win32::OLE->LastError()} ; #<<<< PROBLEM LINE SEE FEEDBACK BELOW
if ( $err){
print $ERROR "WIN32::OLE raised an exception: $err\n";
Win32::OLE->LastError(0); # this clears your error
}
My thinking is that I am using eval
to detect the existence of the error object and on the Win32:OLE
module to detects the error and reports it.
Am I safe to ignore the criticism?
Leaving aside the
perl-critic
issuse, your code does not make much sense.The Win32::OLE docs explain when exceptions will be thrown (and how you can automatically catch them).
LastError
just gives you information about an error after it has occurred assuming your program has not died. Wrapping it ineval
is pointless.Update: I would have written something along the following lines (untested because I am on Linux with no access to Windows right now):