[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Exceptions on JVM [was: Exceptions needs examples]

On 1/8/2014 9:43 PM, Per Bothner wrote:
> To change Kawa's implementation I need example code that fails, 
> preferably
> in a form suitable for the test-suite.  (Unless it's to improve the 
> performance,
> but that is not the issue here, I think.)  But not only that: A test that
> is part of a test-case but uses convoluted unnatural idioms (while useful
> for a testsuite) is obviously relatively lower priority, especially if
> it is difficult to implement correctly or excessively hurts performance.

I am not suggesting that you change Kawa's implementation. I was 
offering a possible implementation strategy that worked for Foment and 
seemed like it might have benefited Kawa.

>> Here is a possible solution:
>> If exceptions thrown by Java code get turned into Scheme exceptions
>> before the dynamic environment gets unwound, then it should be possible
>> to get very close to the full semantics for 'guard' and
>> 'with-exception-handler' without too much overhead. This can be done by
>> putting try-catch around the <body> of 'parameterize' and 'guard', and
>> the <thunk> of 'dynamic-wind'.
>> (define-syntax parameterize
>>       (syntax-rules ()
>>           ((parameterize ((param value) ...) . body)
>>                   <set params to values> (try-catch body (ex (raise 
>> ex))))))
> I don't understand how this try-catch does anything.

The idea is that the 'try-catch' turns Java exceptions into Scheme 
exceptions before any of the dynamic environment gets unwound. 
'try-catch' catches the Java exception and 'raise' re-raises it using 
Scheme exception handling -- for this to work, all of the dynamic 
environment needs to be in Scheme land. Note that 'raise' is probably 
not the existing Kawa 'raise'. The benefit is that exception handlers 
get executed in the correct dynamic environment.

Scheme-reports mailing list