I was listening to the recent IO conversation on p6c, and decided to look at IO.pm in rakudo. I immediately saw a bit of code that worried me:
try { ?$!PIO.close() } $! ?? fail($!) !! Bool::True Why is that so cumbersome? That seems like one of the most obvious use-cases for exceptions. I looked over the synopses and tested some theories, but what I came to was inconclusive. It seems like: return try { die "oops" } has undefined behavior because the return value of try is not clearly spelled out (one might expect it to be the return value of the statement, but that's not said anywhere, though it's backhandedly implied by an example where try is used like do). Right now, the above causes a Null PMC access in Rakudo, but that might just be a limitation in the implementation, rather than an indication that try is not intended to have a return value. I'd like to suggest that try's semantics should be defined and clearly stated in S04/"Other do-like forms" as: Try returns either the block's normal return value or the relevant, unthrown exception. Thus the above IO example becomes (with no changes in the grammar): try { ?$!PIO.close(); Bool::True } The golfer in me wants ? to take an adverb that causes this to all be moot: ? :true $!PIO.close() but I know that's probably going a bit too far, and I'd like to think it's too late for that kind of feature request. =