[CM] s7: bubbling up errors (bug?)

bil at ccrma.Stanford.EDU bil at ccrma.Stanford.EDU
Sat Jul 18 13:01:32 PDT 2020


throw is (throw tag . info), that is it takes its trailing args and puts 
them
in a list.  The first throw gets the args: 'some-error "..." 1.  It 
passes
these as: 'some-error ("..." 1) to the first error handler (that's why 
you
can apply format to cadr -- cadr has been turned into a list).  You 
throw
that again using apply, so its args the second time are: some-error 
'("..." 1),
(I'm trying to show that the second call is not like the first -- it has
only one trailing arg, the list '("..." 1).  Once again throw treats it 
as
a rest arg, and puts it in a list, then the second error handler sees:
some-error (("..." 1)).  If you want to rethrow, the second throw needs
to match the first one, use (apply throw (car args) (cadr args)).
It might be better to use (lambda (type info) for the error handler,
so you can say

(catch #t
   (lambda ()
     (catch #t
       (lambda ()
	(throw 'some-error "::: ERROR ::: (~A)~%" 1))
       (lambda (type info)
	(apply format *stderr* info)
	(apply throw type info))))
   (lambda (type info)
     (apply format *stderr* info)
     ))



More information about the Cmdist mailing list