Is it better to croak() or to die() when something bad happens in Perl?

后端 未结 6 1220
无人及你
无人及你 2021-02-18 22:12

perlcritic complaints that the following code, some boilerplate DBI stuff that works perfectly fine, should croak instead of die:

# Connect to database
my $db_ha         


        
6条回答
  •  忘掉有多难
    2021-02-18 22:34

    Still. This example may want to use croak if the connection parameters came directly from the inputs to the function as others pointed out.

    If you write a test for yourself that triggers the exception then you will be your own client and appreciate which is better.

    If it is very hard to test error condition it may be a case for die over croak. But any parameter validating errors should use croak.

提交回复
热议问题