Page 1 of 1

Catch error message in SBCL

Posted: Wed Jun 12, 2019 12:28 pm
by julienvincenot
Hi,

I wonder if there is a way in SBCL and CL in general, whenever any kind of error happens (undefined variable, division by zero, type error, etc.),
to prevent the debugger from popping up and then catch the error message string to display it / write it somewhere else.

Basically, I'm controlling SBCL via shell commands from inside another environment (MaxMSP).
My system in Max aims at teaching Lisp to musicians with dynamic visual interfaces,
so I want my users to be able to understand what's going on without going to the terminal themselves.

The shell object in Max can send shell commands and get its results successfully (anything that went through a PRINT function in SBCL)
but the debugger doesn't seem to take place in the same space.

Let's say I send the following command :
sbcl --core some/path/to/a/.core/file --script my/script/generated/in/maxmsp

If there's an error inside my script, in the terminal the debugger would show up then quit immediately — but Max would just show nothing until the next valid script.

What I would like to do is intercept the error message, such as
"The value 'TOTO is not of type NUMBER when binding SB-KERNEL::X",
without having to create all kinds of exceptions.

Any suggestions will be highly welcome, thanks in advance !
Best,

Julien

Re: Catch error message in SBCL

Posted: Sat Jun 15, 2019 4:46 pm
by pjstirling
*DEBUGGER-HOOK* seems to be what you want?

http://www.lispworks.com/documentation/ ... ger-hookST

Re: Catch error message in SBCL

Posted: Wed Jul 01, 2020 3:43 pm
by vindarel
Hello a bit late :)

What about simply catching all conditions with `handler-case` and printing the condition, with a regular `(format t "~a" …)`?

Code: Select all

        
        (handler-case
            (start-the-core-app)
          (error (c)
            (format t "An unexpected error happened: ~a" c)))