i'm playing around perl 6's control exceptions. warn raises control exception invisible normal exception control flow, , exception resumes itself. that's kinda cool.
so, playing around this, wrote see happen. i'm not trying solve particular problem other seeing perl 6 does:
use v6; try { control { put "caught exception, in try"; put .^name; } do-that-thing-you-do(); } sub do-that-thing-you-do { control { put "caught exception, in sub"; put .^name; } warn "this warning"; }
it looks both fire:
caught exception, in sub cx::warn caught exception, in try cx::warn warning in sub do-that-thing-you-do @ resume.p6 line 16 moarvm panic: trying unwind on wrong handler
notice there's moar panic, i've raise issue for. but, i'm not asking that.
i'm curious picture of flow here. expected control
in sub catch exception , resume, wouldn't percolate try
. how should flow?
also, notice exception cx::warn
. don't think i've done odd there, perl 6 types don't list x::warn
to same behavior default warnings handler, it's necessary both catch exception (as catch
, control
without smart-matching re-throw) , resume
after it.
control { when cx::warn { "warning: $_"; .resume } } sub foo() { 1; warn 'oh gosh...'; 2; # not reached without .resume } foo();
there many other control exceptions, , wise match on cx::warn
rather use default
. otherwise, take
, next
, last
, emit
, done
(and, in 6.d, await
) netted handler, surely make quite headaches.
Comments
Post a Comment