[plt-scheme] handling user-breaks in MrEd app...

From: Jefferson Provost (jp at cs.utexas.edu)
Date: Wed Oct 30 18:58:45 EST 2002


I'm writing a graphical MrEd app, and though most interaction will be 
through graphical objects, I want to run a repl for debugging and other 
stuff.  I don't want to use MrEd's graphical repl, but when I do mred 
-z, the stdio repl never yields to give events/time to my graphical 
objects.  My solution is to instantiate my graphical objects, and then 
run a stdio repl in a separate, as in the code below.

The problem is that the with-handlers form seems to swallow all 
exceptions (other than exn:break) without any notification.  Without the 
with-handlers, breaks (ctrl-C's) send the program into some inscrutable 
state in which there's still a repl running (the top-level repl?) but 
the program is basically unusable.

I guess I don't understand how handlers work, because I assumed that 
handling one kind of exception wouldn't change how the others were 
handled, but that's not what's happening.  What's going on?


   (define (gui-repl)
     (let ((t (thread read-eval-print-loop)))
       (let loop ()
	(sleep 0.01)
	(if (thread-running? t) (loop)))))

; instantiate my window(s) here

(define my-console (instantiate my-graphical-console% () )
(send my-console show #t)

; start the repl
   (with-handlers ((exn:break? (lambda (x)
   			       (display (format "\nuser break!\n"))

The problem with this is that errors generated from my-console (or the 
windows it spawns) just vanish.  If I run mred w/o "-z", and comment out 
everything below ";start the repl", then errors get printed to stdout

Posted on the users mailing list.