How to properly use the try catch in perl that error.pm provides?

前端 未结 4 704
南旧
南旧 2021-02-03 20:04

I have found that there is the module Error that provides try and catch functionality like in java. But I am confused at how you can print the exception that returns.

I

4条回答
  •  旧巷少年郎
    2021-02-03 20:32

    You're probably better off using Try::Tiny which will help you avoid a number of pitfalls with older perls.

    use Try::Tiny;
    
    try {
            die "foo";
    } catch {
            warn "caught error: $_";
    };
    

提交回复
热议问题