Suppressing error message "-- an error. To debug this try: debugmode(true); "
Subject: Suppressing error message "-- an error. To debug this try: debugmode(true); "
From: Stefano Ferri
Date: Sat, 1 Dec 2012 17:51:44 +0100
2012/12/1 Robert Dodier <robert.dodier at gmail.com>
> On 2012-12-01, Stefano Ferri <ferriste at gmail.com> wrote:
>
> > As an alternative, I could print a message with "print" and then stop the
> > program in some way.... but is there such a "stop" or "exit" command
> > implemented?
>
> Well, from looking at src/merror.lisp there are various ways to handle
> errors. Probably the only way to get exactly what you want is to write a
> line or two of Lisp code.
>
I know pretty nothing about Lisp, but looking at merror.lisp I've created
and loaded a file "myerror.lisp" which simply redefines "merror":
(defun merror (sstring &rest l)
(declare (special errcatch *mdebug*))
(setq $error `((mlist) ,sstring ,@ l))
(and $errormsg ($errormsg))
(cond (*mdebug*
(let ((dispflag t) ret)
(declare (special $help dispflag))
(format t (intl:gettext " -- an error. Entering the Maxima
debugger.~%~
Enter ':h' for help.~%"))
(progn
(setq ret (break-dbm-loop nil))
(cond ((eql ret :resume)
(break-quit))))))
(errcatch (error 'maxima-$error))
(t
(fresh-line *standard-output*)
($backtrace 3)
(format t (intl:gettext "~%"))
(throw 'macsyma-quit 'maxima-error))))
It is the same code of the original merror, except for the second to last
line in which
(format t (intl:gettext "~& -- an error. To debug this try:
debugmode(true);~%"))
has been replaced by a simple
(format t (intl:gettext "~%"))
which only prints a new line. It works perfectly but maybe it is a ugly
solution... How can I avoid to rewrite all the function and redefine only
the "format t (....." line?
Even if ugly, could it be a correct solution?
> * assign ?errcatch:true and call error("my msg") as before. I see in
> src/merror.lisp that that suppresses the bit about launching the
> debugger.
>
It suppresses the "-- an error. To debug this try: debugmode(true);", but
the output is even worse:
(%i24) error("my msg");
my msg
Maxima encountered a Lisp error:
my msg
Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
> * define your own function which uses Maxima's throw/catch mechanism.
> E.g.: myerror (msg) := (print (msg), throw ('oops));
> throw/catch is a nonlocal flow of control mechanism, maybe that's
> what you want.
>
I'll look at this way too, but I would lose the information contained in
errormsg(), which sometimes is useful.
Thanks for your help.
Stefano