Skip to content

Commit

Permalink
FEAT: any TRY call resets system/state/last-error to none
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jul 3, 2020
1 parent f68e855 commit 88cd91b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/n-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,13 +834,13 @@ enum {
{
REBFLG except = D_REF(2);
REBVAL handler = *D_ARG(3); // TRY exception will trim the stack
REBVAL *last_error = Get_System(SYS_STATE, STATE_LAST_ERROR);
SET_NONE(last_error);

if (Try_Block(VAL_SERIES(D_ARG(1)), VAL_INDEX(D_ARG(1)))) {
// save the error as a system/state/last-error value
*last_error = *DS_NEXT;
if (except) {
// save it for access from the block handler or explain
REBVAL *val = Get_System(SYS_STATE, STATE_LAST_ERROR);
*val = *DS_NEXT;

if (IS_BLOCK(&handler)) {
DO_BLK(&handler);
}
Expand Down
7 changes: 7 additions & 0 deletions src/tests/units/evaluation-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ Rebol [
--assert error? system/state/last-error
--assert system/state/last-error/id = 'zero-divide
]
; any TRY call resets system/state/last-error to none:
--assert not error? try [1 + 1]
--assert none? system/state/last-error
; the last-error is stored also when /except is not used:
--assert error? try [this-is-error]
--assert error? system/state/last-error

--test-- "try/except [1 / 0] function!"
system/state/last-error: none
--assert string? try/except [1 / 0] :mold
Expand Down

0 comments on commit 88cd91b

Please sign in to comment.