File tree Expand file tree Collapse file tree 1 file changed +50
-1
lines changed Expand file tree Collapse file tree 1 file changed +50
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
# Tests for try and catch
4
4
5
- plan (55 );
5
+ plan (57 );
6
6
7
7
sub oops ($ msg = " oops!" ) { # throw an exception
8
8
nqp ::die($ msg );
@@ -464,3 +464,52 @@ sub scope2() {
464
464
}
465
465
466
466
scope2();
467
+
468
+ sub catch_with_control ($ throws ) {
469
+ my $ caught ;
470
+ my sub caught ($ arg ) {
471
+ $ caught := $ arg ;
472
+ }
473
+ nqp ::handle(
474
+ $ throws (),
475
+ ' CONTROL' , caught(' control' )
476
+ );
477
+ $ caught ;
478
+ };
479
+
480
+ sub catch_labeled ($ throws ) {
481
+ my $ caught ;
482
+ my sub caught ($ arg ) {
483
+ $ caught := $ arg ;
484
+ }
485
+ my $ ret := nqp ::handle(
486
+ $ caught := $ throws (),
487
+ ' LABELED' , Label2,
488
+ ' TAKE' , caught(' labeled' )
489
+ );
490
+ $ caught ;
491
+ };
492
+
493
+ sub catch_unlabeled ($ throws ) {
494
+ my $ caught ;
495
+ my sub caught ($ arg ) {
496
+ $ caught := $ arg ;
497
+ }
498
+ nqp ::handle(
499
+ $ caught := $ throws (),
500
+ ' TAKE' , caught(' unlabeled' )
501
+ );
502
+ $ caught ;
503
+ };
504
+
505
+ is (catch_unlabeled({
506
+ catch_with_control({
507
+ THROW(nqp ::const::CONTROL_TAKE, nqp ::null())
508
+ });
509
+ }), ' control' , ' an unlabeled exception is caught by CONTROL' );
510
+
511
+ is (catch_labeled({
512
+ catch_with_control({
513
+ THROW(nqp ::add_i(nqp ::const::CONTROL_TAKE, nqp ::const::CONTROL_LABELED), Label2)
514
+ });
515
+ }), ' control' , ' a labeled exception is caught by CONTROL' );
You can’t perform that action at this time.
0 commit comments