开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜