Skip to content

Commit 7e25856

Browse files
committed
FIX: better error messages for not caught throws
1 parent 6e00115 commit 7e25856

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/boot/errors.reb

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Throw: [
1919
type: "throw error"
2020
break: {no loop to break}
2121
return: {return or exit not in function}
22-
throw: [{no catch for throw:} :arg1]
22+
unnamed-throw: [{no catch for unnamed throw with value:} :arg1]
23+
throw: [{no catch for throw:} :arg2 "with value:" :arg1]
2324
continue: {no loop to continue}
2425
halt: [{halted by user or script}]
2526
quit: [{user script quit}]

src/core/s-mold.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,8 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
10461046
{
10471047
ERROR_OBJ *err;
10481048
REBVAL *msg; // Error message block
1049+
REBCNT sym;
1050+
REBVAL word;
10491051

10501052
// Protect against recursion. !!!!
10511053

@@ -1062,9 +1064,21 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
10621064
return;
10631065
}
10641066

1065-
// If it is an unprocessed BREAK, THROW, CONTINUE, RETURN:
1066-
if (VAL_ERR_NUM(value) < RE_NOTE || !VAL_ERR_OBJECT(value)) {
1067-
VAL_ERR_OBJECT(value) = Make_Error(VAL_ERR_NUM(value), value, 0, 0); // spoofs field
1067+
// If it is an unprocessed THROW:
1068+
if (VAL_ERR_NUM(value) == RE_THROW) {
1069+
sym = VAL_ERR_SYM(value);
1070+
if (!sym) {
1071+
VAL_ERR_OBJECT(value) = Make_Error(RE_UNNAMED_THROW, VAL_ERR_VALUE(value), 0, 0);
1072+
}
1073+
else {
1074+
Set_Word(&word, sym, 0, 0);
1075+
VAL_SET(&word, REB_WORD);
1076+
VAL_ERR_OBJECT(value) = Make_Error(VAL_ERR_NUM(value), VAL_ERR_VALUE(value), &word, 0);
1077+
}
1078+
}
1079+
// If it is an unprocessed BREAK, CONTINUE, RETURN:
1080+
else if (VAL_ERR_NUM(value) < RE_NOTE || !VAL_ERR_OBJECT(value)) {
1081+
VAL_ERR_OBJECT(value) = Make_Error(VAL_ERR_NUM(value), VAL_ERR_VALUE(value), 0, 0); // spoofs field
10681082
}
10691083
err = VAL_ERR_VALUES(value);
10701084

0 commit comments

Comments
 (0)