问题描述
投诉,以下代码,一些样板DBI的东西工作得很好,应该而不是
perlcritic complaints that the following code, some boilerplate DBI stuff that works perfectly fine, should croak
instead of die
:
# Connect to database
my $db_handle = DBI->connect( $url, $user, $password ) or die $DBI::errstr;
所有这一切,在死亡似乎对我来说很好。
All this, while die seems to work fine for me.
我会想到一个武士Perl战士,呱呱呱呱。able able able when when when when。。。。。。笑话分开
I would think for a samurai Perl warrior, croak is less honorable than actually die when things go awry. Jokes apart
为什么我应该 croak
而不是 die
?
Why should I croak
instead of die
?
不注意的是什么后果建议?
What are the consequences of not heeding perlcritic's advice?
推荐答案
从
在这种情况下,错误(DB的连接错误)没有任何关系的呼叫者和所有的事情做线连接,所以我会使用死
。
In this case, the error (connection error to DB) has nothing to do with the caller and everything to do with the line making the connection, so I would use die
.
这篇关于当Perl发生不好的事情时,最好呱呱叫()还是死()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!