diff --git a/runtime.c b/runtime.c index dccc07fe..74a0f719 100644 --- a/runtime.c +++ b/runtime.c @@ -708,22 +708,27 @@ object Cyc_default_exception_handler(void *data, object _, int argc, int is_msg = 1; fprintf(stderr, "Error: "); - if ((err == NULL) || is_value_type(err) || type_of(err) != pair_tag) { + if ((err == NULL) || is_value_type(err) || type_of(err) != pair_tag || !Cyc_is_symbol(car(err))) { Cyc_display(data, err, stderr); } else { - // Error is list of form (type arg1 ... argn) - err = cdr(err); // skip type field - for (; (err != NULL); err = cdr(err)) { // output with no enclosing parens - if (is_msg && is_object_type(car(err)) && type_of(car(err)) == string_tag) { - is_msg = 0; - Cyc_display(data, car(err), stderr); - if (cdr(err)) { - fprintf(stderr, ": "); + if (strncmp(((symbol) car(err))->desc, "error", 10) == 0) { + // Error is list of form (type arg1 ... argn) + err = cdr(err); // skip type field + for (; (err != NULL); err = cdr(err)) { // output with no enclosing parens + if (is_msg && is_object_type(car(err)) && type_of(car(err)) == string_tag) { + is_msg = 0; + Cyc_display(data, car(err), stderr); + if (cdr(err)) { + fprintf(stderr, ": "); + } + } else { + Cyc_write(data, car(err), stderr); + fprintf(stderr, " "); } - } else { - Cyc_write(data, car(err), stderr); - fprintf(stderr, " "); } + } else { + fprintf(stderr, "raised object: "); + Cyc_display(data, cdr(err), stderr); } } diff --git a/scheme/base.sld b/scheme/base.sld index 93cda120..a57279e2 100644 --- a/scheme/base.sld +++ b/scheme/base.sld @@ -1251,13 +1251,16 @@ (define error-object-message car) (define error-object-irritants cdr) (define (error msg . args) - (raise (cons msg args))) + (raise-error (cons msg args))) (define (raise obj) ((Cyc-current-exception-handler) - (cons 'raised (if (pair? obj) obj (list obj))))) + (cons 'raised obj))) (define (raise-continuable obj) ((Cyc-current-exception-handler) - (cons 'continuable (if (pair? obj) obj (list obj))))) + (cons 'continuable obj))) + (define (raise-error obj) + ((Cyc-current-exception-handler) + (cons 'error obj))) ;; A simpler exception handler based on the one from Bigloo: ;; https://www-sop.inria.fr/indes/fp/Bigloo/doc/bigloo-17.html#g20889 ;(define (with-handler handler body)