[racket] again: timeouts and exceptions

From: Rüdiger Asche (rac at ruediger-asche.de)
Date: Thu Jul 5 09:42:13 EDT 2012

Hi there,

a few of you recommended to implement timeouting reads via  
sync/timeout. That works neat, but it would be even nicer to combine  
this w/ exception handling, like so:

     (lambda (port)
             (if (sync/timeout READTIMEOUT inport)
	       (read-byte inport)
	       (raise "read-byte" #t))))
((readsomething) ..... (readbytetimeout) ......

(letrec ((repl (lambda ()
                 (let ((readresult
		      (call-with-exception-handler HandlerFn

Iow, I want the REPL to always be operational but restart from the  
beginning when the innermost read timeouts so that the periodic  
computations get their turn.

I didn't get this to work though because according to the docs, "If the
exception handler returns a value when invoked by raise, then raise
propagates the value to the “previous” exception handler (still in the
dynamic extent of the call to raise, and under the same barrier, if any)."

That is true; I get thrown back out of the entire thing because the  
default uncaught exception handler is called. What ectually does it  
mean "IF the
exception handler..." How is it possible for a function NOT to return a value?
Any return value including #f and () will propagate the exception to the
default handler; I simply want to stop it where it is.

What do I need to do (or paraphrased: What is the necessary  
implementation of HandlerFn) in order to get this to work? Or do I  
need yet another control flow or handling mechanism?


Posted on the users mailing list.