From: David Simmons Date: 2001-07-19T23:41:10+09:00 Subject: [ruby-talk:18121] Re: Exceptions "Yukihiro Matsumoto" wrote in message news:iAx57.28006$PF1.1401786@e420r-atl2.usenetserver.com... > Hi, > > In message "[ruby-talk:18102] Re: Exceptions" > on 01/07/19, "Aleksei Guzev" writes: > > |Can one implement such "resume" without changing the ruby core itself? > > No. It requires deep core rewrite. Not an easy task at all. > > matz. > If I understand it correctly, Ruby provides real/complete block closures? If so, you might find it useful to review the 1998 ANSI Smalltalk Standard. The rich exception model it provides can all be built in pure Smalltalk code based on using block closures. If Ruby has real/complete block closures, someone should be able to provide a full featured set of portable exceptions by writing a library directly in Ruby code itself. The Smalltalk exception model supports: ACTIONS WITHIN A GUARD/FILTER: ----------------------------- pass - don't handle the exception resume - continue execution from the exception signalling expression. Optionally allows replacing the return value. return - unwind intervening guards and exit from this guard. Optionally allows replacing the return value. outer - calculate the result/status of invoking an outer guard. Allows an inner guard to call outer guards while leaving the inner guard in control of what happens next. resignalAs - restart the exception handling from the signalling expression but substitute and alternate exception. retry - exit the currently guarded context and retry the execution of that context (the try block). retryUsing - exit the currently guarded context and retry using the supplied block [within the current guard context] instead of the original "try" block. break - is equivalent to "return:" Other useful items that can be queried are: isCurtailed isException isSignal isResumable isNested signalValue signallingContext [from which you can walk all the intermediate frames] unwindContext walk the nested (outer) guard contexts, etc. Various implementations, like my work with QKS Smalltalk (and SmallScript) actually have a richer model than that which is provided by the ANSI standard [because the standard had to be a common and easily implementable subset of available implementation features such as those which were in QKS Smalltalk at the time the standard was written]. My work actually is unified with C++ (and SEH) facilities on its various platforms, and directly into the .NET exception system on the .NET platform. Based on my experiences, it is only moderately hard work to implement all the above features as essentially zero cost exception handling. Where all the "blocks" actually become inlined subroutines (since none of them are actually capturable). The key is to integrate it directly into the non-local return [unwind] semantics of the languages execution engine (VM). -- -- Dave S. [ http://www.smallscript.net ]