On Wed, Jan 27, 2016 at 11:06 AM, Felipe Gasper <fel...@felipegasper.com>
wrote:

> On 27 Jan 2016 11:03 AM, Brandon Allbery wrote:
>>
>> On Wed, Jan 27, 2016 at 11:00 AM, Felipe Gasper <fel...@felipegasper.com
>> <mailto:fel...@felipegasper.com>> wrote:
>>
>>     Unrelated, but, does open() not throw on failures anyway? (Noodling
>>     with the perl6 REPL just now seems inconclusive.)
>>
>> There have been issues with failures in sink context not throwing, IIRC?
>> So how you were noodling can matter.
>>
>
> felipe@Macintosh-3 00:45:46 /
> > perl6
> > open("/dfgsgsdfgd", :r);
> Failed to open file /dfgsgsdfgd: no such file or directory
> > my $f = open("/dfgsgsdfgd", :r);
> Failed to open file /dfgsgsdfgd: no such file or directory
> > print $f;
> (HANDLED) Failed to open file /dfgsgsdfgd: no such file or directory
>   in any  at
> /Users/felipe/.rakudobrew/moar-2015.12/install/share/perl6/runtime/CORE.setting.moarvm
> line 1
>   in block <unit> at <unknown file> line 1
>

Looks to me like both of them threw? and $f is set to the Failure object
instead of a filehandle, which has an annotation saying that it was indeed
handled (thrown).

Perl 6 has two ways to indicate failure: you can throw immediately, or you
can return a Failure object which is a "lazy exception". The latter allows
a program to introspect the return value to recognize and handle a Failure
without actually throwing it (faster and often cleaner than catching it),
or if something just tries to use the value without checking then it throws
at that point. It remembers the context in which it was created, so the
traceback should indicate that it happened in the open call.

-- 
brandon s allbery kf8nh                               sine nomine associates
allber...@gmail.com                                  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

Reply via email to