如何正确使用try.pm提供的perl中的try catch? [英] How to properly use the try catch in perl that error.pm provides?
本文介绍了如何正确使用try.pm提供的perl中的try catch?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现有一个模块错误提供try和catch功能,如java 。但是我感到困惑的是如何打印返回的异常。
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.
我想了解如何执行以下
try {
// do something that will fail!
} catch (Error e) {
// Print out the exception that occurred
System.out.println(e.getMessage());
}
如何使用堆栈跟踪获取错误的打印? p>
How do I get the print of the error with the stack trace?
推荐答案
你最好使用 Try :: Tiny ,这将帮助您避免一些较旧的 perl
s 。
You're probably better off using Try::Tiny which will help you avoid a number of pitfalls with older perl
s.
use Try::Tiny;
try {
die "foo";
} catch {
warn "caught error: $_";
};
这篇关于如何正确使用try.pm提供的perl中的try catch?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文