开发者

pdf reuse .... how to warn if there's an error (rather than just die)

开发者 https://www.devze.com 2023-01-22 15:54 出处:网络
I am using PDF::Reuse to write a new pdf: use PDF::Reuse; prFile( $copyPdf ); prDoc( $old ) ; prEnd(); works great but if there\'s an error, the entire 开发者_如何学Cscript dies...how can I inste

I am using PDF::Reuse to write a new pdf:

use PDF::Reuse;                      
prFile( $copyPdf ); 
prDoc( $old ) ; 
prEnd();

works great but if there's an error, the entire 开发者_如何学Cscript dies...how can I instead just "warn" if Reuse encounters a problem?


Wrap it in a block eval:

use PDF::Reuse;                      

eval {
    prFile( $copyPdf ); 
    prDoc( $old ) ; 
    prEnd();
    1;
} or warn $@;

Or better yet, use Try::Tiny (it does the same thing but in a safer way):

use Try::Tiny;
use PDF::Reuse;                      

try {
    prFile( $copyPdf ); 
    prDoc( $old ) ; 
    prEnd();
} catch {
    warn $_;
};
0

精彩评论

暂无评论...
验证码 换一张
取 消