加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在Perl发生不好的情况下,最好是呱呱叫()还是死()?

发布时间:2020-12-15 22:00:57 所属栏目:大数据 来源:网络整理
导读:perlcritic投诉以下代码,一些样板DBI的东西工作完美,应该 croak 而不是 die : # Connect to databasemy $db_handle = DBI-connect( $url,$user,$password ) or die $DBI::errstr; 所有这一切,虽然死了似乎对我来说很好. 我会想到一个武士的Perl战士,呱呱呱
perlcritic投诉以下代码,一些样板DBI的东西工作完美,应该 croak而不是 die
# Connect to database
my $db_handle = DBI->connect( $url,$user,$password ) or die $DBI::errstr;

所有这一切,虽然死了似乎对我来说很好.

我会想到一个武士的Perl战士,呱呱呱呱.able able able able when when……..笑话分开

为什么要cro ak而不是死?

没有注意perlcritic’s的建议有什么后果?

解决方法

从 http://www.perlmonks.org/?node_id=685452

You use die when the error is something you or your code didn’t do right. You use croak when it’s something your caller isn’t doing right. die “error: $!” indicates the error is on the line where the error occured. croak “error: $!” indicates the error is on the line where the caller called your code.

在这种情况下,错误(连接到DB的错误)与调用者无关,并且与进行连接的行有关,所以我会用死.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读