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

后端 未结 6 1187
无人及你
无人及你 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:36

    It's not necessarily wrong to use die() but croak() gives you or your user a lot more information about what went wrong. There's also variables that can be set in the Carp namespace that can change this output to get more or less information.

    It's equivalent to die() but with more information and control.

提交回复
热议问题