@@ -413,11 +413,11 @@ enum {
413
413
REBVAL * val ;
414
414
REBVAL * ret ;
415
415
REBCNT sym ;
416
- REBVAL recover = * D_ARG (ARG_CATCH_RECOVER );
416
+ REBVAL recover = * D_ARG (ARG_CATCH_CODE );
417
417
REBVAL * last_result = Get_System (SYS_STATE , STATE_LAST_RESULT );
418
418
REBOOL quit ;
419
419
420
- if (D_REF (ARG_CATCH_QUIT )) { //QUIT
420
+ if (D_REF (ARG_CATCH_QUIT )) {
421
421
quit = Try_Block_Halt (VAL_SERIES (D_ARG (ARG_CATCH_BLOCK )), VAL_INDEX (D_ARG (ARG_CATCH_BLOCK )));
422
422
ret = DS_NEXT ;
423
423
if (quit ) {
@@ -445,32 +445,41 @@ enum {
445
445
446
446
// If it is a throw, process it:
447
447
if (IS_ERROR (ret ) && VAL_ERR_NUM (ret ) == RE_THROW ) {
448
+ // Get optional thrown name
449
+ sym = VAL_ERR_SYM (ret );
448
450
449
- // If a named throw, then check it:
450
- if (D_REF (ARG_CATCH_NAME )) { // /name
451
+ if (D_REF (ARG_CATCH_ALL )) goto caught ;
451
452
452
- sym = VAL_ERR_SYM (ret );
453
- val = D_ARG (ARG_CATCH_WORD ); // name symbol
453
+ // If a named catch, then check it:
454
+ if (D_REF (ARG_CATCH_NAME )) {
455
+ val = D_ARG (ARG_CATCH_WORD ); // catch/name value
454
456
455
457
// If name is the same word:
456
- if (IS_WORD (val ) && sym == VAL_WORD_CANON (val )) goto got_err ;
458
+ if (IS_WORD (val ) && sym == VAL_WORD_CANON (val )) goto caught ;
457
459
458
460
// If it is a block of words:
459
461
else if (IS_BLOCK (val )) {
460
462
for (val = VAL_BLK_DATA (val ); NOT_END (val ); val ++ ) {
461
- if (IS_WORD (val ) && sym == VAL_WORD_CANON (val )) goto got_err ;
463
+ if (IS_WORD (val ) && sym == VAL_WORD_CANON (val )) goto caught ;
462
464
}
463
465
}
466
+ //else if (IS_LOGIC(val) && VAL_LOGIC(val)) goto caught; // used CATCH/name [] true
464
467
} else {
465
- got_err :
468
+ // Used catch without name. If there was thrown a name, then let it pass thru.
469
+ if (sym != 0 ) {
470
+ * DS_RETURN = * ret ;
471
+ return R_RET ;
472
+ }
473
+ caught : // Thrown is being caught.
474
+ // Store thrown value as the last result.
466
475
* ds = * (VAL_ERR_VALUE (ret ));
467
476
* last_result = * ds ;
477
+ // If there is a recovery code, then evaluate it.
468
478
if (IS_BLOCK (& recover )) {
469
479
DS_NEXT ;
470
480
DO_BLK (& recover );
471
481
DS_POP ;
472
- }
473
-
482
+ }
474
483
return R_RET ;
475
484
}
476
485
}
0 commit comments