From: Paul Brannan Date: 2003-07-28T23:53:24+09:00 Subject: Re: Throwing exceptions into continuations. On Sun, Jul 27, 2003 at 10:53:42AM +0900, Christopher Armstrong wrote: > Hi all. I'm playing around with Ruby because I like experimenting with > concurrency systems, and found out it has continuations. > > I'm going to be calling user-defined code inside of a callcc block, > and the user-defined code will either return a value or raise an > error, and I want that value or error to be passed on to the > continuation. Is there a reason why you are using continuations for this? Perhaps some other construct like procs or threads would work better. > I can't find any way to throw into the continuation. If there is no > way, can I request that a #throw method be added, or something like > that? I'm not entirely sure what you mean by "throw into". Do you want to cause an exception to occur in the middle of the user-defined code? There is a Thread#raise, if you want to use a thread. You can stop the thread if you want it to stop running for a while. > The only alternative I could think of is to have special code on the > calling side of the callcc that will watch the return value to see if > it is a array of two elements, the first being > :special-internal-throw-exception-bit, and if so, throwing the second > element of the array. This isn't what I want, though, especially > because it won't maintain the stack trace from the other side. You might be interested in what I did here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/rubycollections/rubycollections/rbc/iterator/continuation_iterator.rb?rev=1.17&content-type=text/vnd.viewcvs-markup There are two continuations: one doing the iterating and one waiting for the next item from the iteration. The iteration loop is wrapped with a begin/rescue block, and if I get the exception, it gets re-raised by the caller with a backtrace that includes both the backtrace of the iteration block and the backtrace of the code that called #next. Not perfect, but it gives me all the information I need when I'm debugging. Paul