Catch error message in SBCL

Discussion of Common Lisp
Post Reply
Posts: 1
Joined: Wed Jun 12, 2019 12:16 pm

Catch error message in SBCL

Post by julienvincenot » Wed Jun 12, 2019 12:28 pm


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 !


Posts: 166
Joined: Sun Nov 28, 2010 4:21 pm

Re: Catch error message in SBCL

Post by pjstirling » Sat Jun 15, 2019 4:46 pm

*DEBUGGER-HOOK* seems to be what you want? ... ger-hookST

Posts: 4
Joined: Tue Sep 24, 2019 8:05 am

Re: Catch error message in SBCL

Post by vindarel » Wed Jul 01, 2020 3:43 pm

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

          (error (c)
            (format t "An unexpected error happened: ~a" c)))

Post Reply