"Neil Jerram" wrote: > [...] please let me know your thoughts on it - > most importantly, of course, whether it answers your > question!
Making the stack with this: s_error_stack = scm_make_stack(SCM_BOOL_T, SCM_EOL); and using the function (scm_t = SCM): void rethrow_error_with_stack (scm_t s_error_stack, scm_t s_error_key, scm_t s_error_args, const char * procname) { scm_t s_port, s_string, s_stack; size_t len; s_stack = scm_make_stack(SCM_BOOL_T, SCM_EOL); len = scm_to_uint(scm_stack_length(s_error_stack)) - scm_to_uint(scm_stack_length(s_stack)) - 1; s_port = scm_open_output_string(); { scm_t s_message = scm_list_ref(s_error_args,scm_from_uint(1)); scm_t s_args = scm_list_ref(s_error_args,scm_from_uint(2)); scm_simple_format(s_port, s_message, (scm_is_eq(SCM_BOOL_F, s_args)? SCM_EOL : s_args)); scm_newline(s_port); scm_display_backtrace(s_error_stack, s_port, scm_from_uint(len), SCM_UNDEFINED); s_string = scm_get_output_string(s_port); } scm_close_output_port(s_port); scm_error_scm(s_error_key, scm_from_locale_string(procname), s_string, SCM_BOOL_F, scm_list_ref(s_error_args, scm_from_uint(3))); } I have error messages like: Backtrace: In unknown file: ?: 0* [dotest "gsl-ode-error-2.4" #<procedure #f ()> ...] ?: 1 (let* () (let* (# #) (let* # #))) ... ?: 2 (begin (display name) (if (thunk? setup) (setup)) ...) ?: 3* (let (# # # ...) (set-current-input-port saved-in) ...) ?: 4* (if catch-error (catch #t thunk (lambda (key . args) key)) (thunk)) ?: 5 [#<procedure #f ()>] ... ?: 6 (let* ((result (quote ()))) (if debugging (newline)) ...) ?: 7* [gsl-ode-evolve #<universal GSL SMOB 404697f8> #:initial-indep-value ...] ?: 8 (let-keywords args #f ...) ... ?: 9 [gsl-p-ode-evolve #<universal GSL SMOB 404697f8> 0.0 ...] <unnamed port>: In procedure gsl-ode-evolve in expression (gsl-p-ode-evolve ode initial-indep-value ...): <unnamed port>: my error message 1 and 2 In unknown file: ?: 10* [#<procedure #f (t y)> 0.0 #,(gsl-vector-real 1 2.0)] ?: 11* [gsl-ode-invoke-fun 0.0 #,(gsl-vector-real 1 2.0) ...] ?: 12 (let* ((o (func t #))) (if (gsl? o) (slot-ref o (quote v)) ...)) ?: 13* [#<procedure #f (t y)> 0.0 #,(gvr 1 2.0)] ?: 14 [throwing-error] ... ?: 15 [scm-error my-own-error "sub-throwing-error" ...] which is not perfect but seems good enough for me. I am a little annoyed that I have to use a port to build the backtrace string, and that the args content is not explicitly documented (that is, I was not able to find it) even if its content is well defined in 'scm_error_scm()': scm_ithrow (key, scm_list_4 (subr, message, args, data), 1); -- Marco Maggi "They say jump!, you say how high?" Rage Against the Machine - "Bullet in the Head" _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user