I just added some enhancements that are a little experimental but likely
to stay in. Discuss please :)
1. Exceptions that bubble all the way out of the main thread, when run
from the command line, are now reformatted Ruby-style:
➔ jruby -rjava -e "raise java.lang.NullPointerException.new"
sun.reflect.NativeConstructorAccessorImpl:-2:in `newInstance0':
java.lang.NullPointerException
from sun.reflect.NativeConstructorAccessorImpl:39:in `newInstance'
from sun.reflect.DelegatingConstructorAccessorImpl:27:in `newInstance'
from java.lang.reflect.Constructor:513:in `newInstance'
from org.jruby.javasupport.JavaConstructor:222:in `new_instance'
My hope is that when folks do get the rare Java exception, either
because they called some library incorrectly or because of a bug in
JRuby, it won't be so terrifyingly un-Ruby this way.
2. Kernel#raise can now raise Java exceptions directly
I don't think there was any way to do this before *at all*, but you can
now instantiate and raise any Java exception object. See above, where
I'm directly raising a NullPointerException instance.
The behavior currently simply checks if the first argument is a Java
Throwable, and then throws it as-is. If it's not a Java throwable, it
calls the default behavior.
3. rescue can now rescue Java exceptions directly
This is the experimental bit. You can now write code like this:
begin
# do something
rescue java.lang.NullPointerException => npe
# report it or whatever
end
It's working correctly for both interpreted and compiled logic.
Basically this just adds a Java catch (Exception e) to rescue logic so
any exceptions passing through will be inspected, like all Ruby
exceptions work. There's a fast path to allow our internal jump
exceptions through without inspection. There are just a few caveats at
the moment:
- You can only catch java.lang.Exception subtypes right now...should I
allow all Throwables?
- The exception object you get out is *not* a NativeException, so if
you're catching NativeException coming out of Java integration now, that
will have to remain in place. Making exceptions coming out of JI no
longer be NativeException would be a breaking change we won't do in 1.1.x.
- It currently depends on the JVM having sun.misc.Unsafe (any
HotSpot-based VM), but I'll be modifying it to eliminate that dependency
soon (maybe tonight).
I've written JI specs for all three new features. Please let me know
what you think.
- Charlie
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email