Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] Why autodie?

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: IKEDA Soji <address@concealed>
  • To: Marc Chantreux <address@concealed>
  • Cc: address@concealed
  • Subject: Re: [sympa-developpers] Why autodie?
  • Date: Thu, 22 Feb 2018 23:42:28 +0900

Hi,

On Thu, 22 Feb 2018 11:17:12 +0100
Marc Chantreux <address@concealed> wrote:

>> So as a typical use case when I open a file and it doesn't exist with
>> autodie?
>
>> if (open (...)) {
>> found ... proceed
>> } elsif ( "File not found" ) {
>> sure, we look elsewhere
>> } else {
>> log the error and handle the problem
>> }
>
>> Actually a better version would be with try and catch - but how does
>> autodie
>> handle that?
>
> i tested it in this file (this is poor testing)
>
> https://github.com/sympa-community/p5-sympatic/blob/master/t/11_use_autodie.t
>
> when $! is rised, $@ is set so if we include Try::Tiny in Sympatic, we
> should be able to write
>
> my $fh =
> try { open ... }
> catch {
> # deal with $ERRNO
> }

Marc, please copy all of what racke wrote using method you supports.

Then how about this?

if (open ...) {
# processing...
return $result;
} elsif ( "File not found" ) {
# Sure, we look elsewhere
return $other;
} else {
# handle the problem
# notify problem to the caller
}


> another option is
>
> my $fh
> { no autodie;
> ...
> }
>
> but again: autodie is about raising exceptions when didn't and provide a
> decent default (as use strict, use warnings).
>
> regards
> marc


--
株式会社 コンバージョン
ITソリューション部 システムソリューション1グループ 池田荘児
〒140-0014 東京都品川区大井1-49-15 アクセス大井町ビル4F
e-mail address@concealed TEL 03-6429-2880
https://www.conversion.co.jp/





Archive powered by MHonArc 2.6.19+.

Top of Page