----- Original Message ----- 
From: "$Bill Luebkert" <[EMAIL PROTECTED]>
To: "perl-win32-users" <[email protected]>
Sent: Tuesday, September 12, 2006 5:18 PM
Subject: Re: Trapping Carp::croak


> Sisyphus wrote:
>
> > Yes, I think you used eval() improperly. You probably wanted:
> >
> > eval {$msg->send};
> >  if (!$@) {
> >      print "message sent\n";
> >  }
> >  else {
> >      print "Failed to send: [EMAIL PROTECTED]";
> >  }
>
> While I would agree that your (and my) method work properly, I
> believe there's nothing wrong with his version either.
>
> His eval should return the result of the send (rather than the
> eval error message) and he's if'ing on that result - so he should
> be fine.

Yes ... I'm not too sure about this. He might be ok in this instance iff
'$msg->send' returns something that evaluates as true.

However, if $msg->send were to *not* return a value (or return 0), then
Howard's code would print "Failed to send: ". Hence, in a general case, it's
a bad practice (though I think you are right that this is not the problem
he's facing here).

As a demo:

use warnings;

if(eval {foo(1)}) {
  print "foo didn't croak\n";
}
else {print "foo croaked: $@"}

sub foo {
    die "gotta croak" if !defined $_[0];
}

__END__

which prints "foo croaked: " even though it didn't croak.

Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to