Skip to content

Commit 989524b

Browse files
committed
COMMON: update error handling
1 parent 35987e7 commit 989524b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/common/brun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ int exec_close_task() {
14421442
prog_timer = NULL;
14431443
}
14441444

1445-
if (prog_error != -1 && prog_error != 0) {
1445+
if (prog_error != errEnd && prog_error != errNone) {
14461446
return 1;
14471447
}
14481448
return 0;

src/common/sberr.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ void err_stack_dump() {
5555
}
5656
}
5757
}
58-
if (prog_stack_count) {
59-
log_printf("\n");
60-
}
6158
}
6259

6360
/**
@@ -75,23 +72,23 @@ void rt_raise(const char *fmt, ...) {
7572
char *buff;
7673
va_list ap;
7774

78-
if (!gsb_last_error && !prog_error) {
75+
if (!gsb_last_error && !prog_error && prog_source) {
7976
prog_error = errRuntime;
8077
va_start(ap, fmt);
8178
buff = malloc(SB_TEXTLINE_SIZE + 1);
8279
vsprintf(buff, fmt, ap);
8380
va_end(ap);
81+
err_stack_dump();
8482
err_common_msg(WORD_RTE, prog_file, prog_line, buff);
8583
free(buff);
86-
err_stack_dump();
8784
}
8885
}
8986

9087
/**
9188
* run-time syntax error
9289
*/
9390
void err_syntax(int keyword, const char *fmt) {
94-
if (!gsb_last_error) {
91+
if (!gsb_last_error && prog_source) {
9592
char *buff = malloc(SB_TEXTLINE_SIZE + 1);
9693
char *fmt_p = (char *)fmt;
9794

@@ -190,7 +187,7 @@ void err_varisnotarray(void) {
190187
}
191188

192189
void err_vararridx(int i, int m) {
193-
rt_raise(ERR_ARRAY_RANGE, i, m);
190+
err_throw(ERR_ARRAY_RANGE, i, m);
194191
}
195192

196193
void err_varnotnum(void) {
@@ -226,7 +223,7 @@ void err_notarray(void) {
226223
}
227224

228225
void err_out_of_range(void) {
229-
rt_raise(ERR_RANGE);
226+
err_throw(ERR_RANGE);
230227
}
231228

232229
void err_missing_sep(void) {
@@ -259,7 +256,7 @@ void err_parm_byref(int n) {
259256
}
260257

261258
void err_stridx(int n) {
262-
rt_raise(ERR_STR_RANGE, n);
259+
err_throw(ERR_STR_RANGE, n);
263260
}
264261

265262
void err_fopen(void) {
@@ -374,6 +371,7 @@ void err_throw_str(const char *err) {
374371
int throw_sp = prog_stack_count;
375372
int try_sp = err_find_try(throw_sp);
376373
int reset_sp;
374+
int trace_done = 0;
377375

378376
if (!prog_error && try_sp != -1) {
379377
bcip_t catch_ip = prog_stack[try_sp].x.vtry.catch_ip;
@@ -413,6 +411,7 @@ void err_throw_str(const char *err) {
413411

414412
if (!caught) {
415413
err_stack_dump();
414+
trace_done = 1;
416415
}
417416

418417
// cleanup the stack
@@ -427,6 +426,9 @@ void err_throw_str(const char *err) {
427426
}
428427
if (!caught) {
429428
prog_error = errRuntime;
429+
if (!trace_done) {
430+
err_stack_dump();
431+
}
430432
err_common_msg(WORD_RTE, prog_file, prog_line, err);
431433
} else {
432434
prog_error = errThrow;

0 commit comments

Comments
 (0)