Ola Bini wrote:
Just noticed a thing, thanks to John Lam. Our JumpExceptions derive from
RuntimeException. That means that code that will catch(Exception) will
stop flow control, if it happens at the wrong place. To get around this,
I believe we should consider going to have JumpExceptions based on
java.lang.Error instead.
Unfortunately this complicates one aspect of Ruby that we still don't
implement correctly: treating inappropriate jumps as LocalJumpError.
Currently, since we generate JumpException instances rather than actual
Ruby exceptions for non-local jump events, we have to catch it in
multiple places and re-wrap it with LocalJumpError. As a result there's
more overhead involved in non-local jumps than just creating and
throwing an exception...there's the Ruby exception-handling mechanisms
to be dealt with as well.
For example, the following code:
def foo(&block)
while true
block.call
end
end
foo { break }
...will successfully break out of the loop, while this code:
def foo(proc)
while true
proc.call
end
end
foo(proc { break })
...will run forever.
Another example:
eval "next"
...produces a LocalJumpError in Ruby but not in JRuby, because we don't
have appropriate code to catch JumpException and turn it into a
LocalJumpError. Or even this code:
begin; return; rescue LocalJumpError; end
...which runs successfully in Ruby but fails in JRuby with a
LocalJumpError because the LJE is created after we leave the code,
rather than immediately when the return event is created.
If we were to move even farther away from JumpException and Ruby
exceptions using the same root types, it would be even harder to make
these behaviors work correctly. Jumps extending Error would also mean
we'd have to catch Errors all over the place in addition to normal Java
exceptions to produce the appropriate Ruby exception types like
LocalJumpError.
I'm keen to solve the catch (Exception) issue, but I'm not sure the
benefits of Error outweigh the detriments.
- Charlie
- Charlie
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email