From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Marco Maggi" Newsgroups: gmane.lisp.guile.user Subject: Re: saving and restoring the error stack trace Date: Thu, 31 Aug 2006 08:04:56 +0200 Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1157004317 1279 80.91.229.2 (31 Aug 2006 06:05:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 31 Aug 2006 06:05:17 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Aug 31 08:05:14 2006 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GIffm-0004qG-5i for guile-user@m.gmane.org; Thu, 31 Aug 2006 08:05:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GIffl-0006X6-9U for guile-user@m.gmane.org; Thu, 31 Aug 2006 02:05:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GIffg-0006W2-IS for guile-user@gnu.org; Thu, 31 Aug 2006 02:05:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GIffe-0006Sr-Tn for guile-user@gnu.org; Thu, 31 Aug 2006 02:05:00 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GIffe-0006Se-MW for guile-user@gnu.org; Thu, 31 Aug 2006 02:04:58 -0400 Original-Received: from [62.241.4.129] (helo=relay-pt3.poste.it) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GIfpD-0001bp-5A for guile-user@gnu.org; Thu, 31 Aug 2006 02:14:51 -0400 Original-Received: from poste.it (192.168.144.52) by relay-pt3.poste.it (7.2.063) (authenticated as marco.maggi-ipsu@poste.it) id 4485AE83001C27C8 for guile-user@gnu.org; Thu, 31 Aug 2006 08:04:56 +0200 X-Sensitivity: 3 Original-To: "guile-user" X-XaM3-API-Version: 4.1 (B107) X-SenderIP: 62.10.55.21 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:5484 Archived-At: "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 =3D scm_make_stack(SCM_BOOL_T, SCM_EOL); and using the function (scm_t =3D 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 =3D scm_make_stack(SCM_BOOL_T, SCM_EOL); len =3D scm_to_uint(scm_stack_length(s_error_stack)) - scm_to_uint(scm_stack_length(s_stack)) - 1; s_port =3D scm_open_output_string(); { scm_t s_message =3D scm_list_ref(s_error_args,scm_from_uint(1)); scm_t s_args =3D 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 =3D 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" # ...] ?: 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 [#] ... ?: 6 (let* ((result (quote ()))) (if debugging (newline)) ...) ?: 7* [gsl-ode-evolve # #:initial-indep-value ...] ?: 8 (let-keywords args #f ...) ... ?: 9 [gsl-p-ode-evolve # 0.0 ...] : In procedure gsl-ode-evolve in expression (gsl-p-ode-evolve ode initial-indep-value ...): : my error message 1 and 2 In unknown file: ?: 10* [# 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* [# 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