Posted on 2009-02-26 14:24:07-08 by sdetweil
setErrorHandler
I have a case where some files being added to the zip are in use by another application. I saw the proposed fix to bug 43359, and I ported that into my 1.26 local copy. but.. this code never gets to execute, as there is a stack dump traceback application fatal error. So, I decided to use the setErrorHandler() routine to trap out and stop the fatal error.. BUT when the error handler would be called in _printerror() in Zip.pm I get another fatal error 'not a CODE reference in Zip.pm line 329, which is the line that invokes the error handler routine..
my code sub ZipErrors() { print @_; } $zip = Archive::Zip->new(); $zip->setErrorHandler( \&lt;ZipErrors ); # repeat as required (some 100 files) $zip->addFile( $file, $zfn ) unless $zip->memberNamed($zfn); $zip->writeToFileNamed($fn); crash... not a CODE reference in Zip.pm line 329 but why? Zip.pm code sub setErrorHandler (&lt;) { my $errorHandler = shift; $errorHandler = \&lt;Carp::carp unless defined($errorHandler); my $oldErrorHandler = $Archive::Zip::ErrorHandler; $Archive::Zip::ErrorHandler = $errorHandler; return $oldErrorHandler; } ###################################################################### # Private utility functions (not methods). sub _printError { my $string = join ( ' ', @_, "\n" ); my $oldCarpLevel = $Carp::CarpLevel; $Carp::CarpLevel += 2; &lt;{$ErrorHandler} ($string); <-------- this line is failing $Carp::CarpLevel = $oldCarpLevel;
Direct Responses: 10084 | Write a response
Posted on 2009-02-27 03:10:55-08 by sdetweil in response to 10075
Re: setErrorHandler
well, this does NOT work
$zip = Archive::Zip->new(); $zip->setErrorHandler( \&lt;ZipErrors );
but THIS does
$zip = Archive::Zip->new(); Archive::Zip::setErrorHandler( \&lt;ZipErrors );
altho the doc uses the first example.. now my error handler gets called.. how can I get the name of the file causing the problem in the handler? Sam
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.