问题描述
投诉以下代码,一些样板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战士,克鲁克比事实变得不实际的死亡不那么荣耀。分开的笑话
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
?
不注意的后果是什么? advice?
What are the consequences of not heeding perlcritic's advice?
推荐答案
从
在这种情况下,错误与调用者无关,并且与使用连接的行做一切,所以我会使用 die
。
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发生不好的事情时,它是更好的croak()还是die()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!