You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rescue Java.type('org.postgresql.util.PSQLException') should work but it does not currently.
It's unclear if a lone rescue should rescue foreign exceptions.
JRuby behavior seems to treat StandardError specially as an ad-hoc way to support lone rescue.
I am not sure we want to follow that.
~ ∴ ruby -e 'begin; p java.lang.Integer.valueOf("abc"); rescue => e; p e; p e.class; p e.class.ancestors; end'
java.lang.NumberFormatException: For input string: "abc"
Java::JavaLang::NumberFormatException
[Java::JavaLang::NumberFormatException, Java::JavaLang::IllegalArgumentException, Java::JavaLang::RuntimeException, Java::JavaLang::Exception, Java::JavaLang::Throwable, Java::JavaIo::Serializable, Java::JavaLang::Object, ConcreteJavaProxy, JavaProxy, JavaProxyMethods, Object, Kernel, BasicObject]
~ ∴ ruby -e 'begin; p java.lang.Integer.valueOf("abc"); rescue RuntimeError => e; p e; p e.class; p e.class.ancestors; end'
Unhandled Java exception: java.lang.NumberFormatException: For input string: "abc"
java.lang.NumberFormatException: For input string: "abc"
forInputString at java/lang/NumberFormatException.java:65
parseInt at java/lang/Integer.java:652
valueOf at java/lang/Integer.java:983
invoke0 at jdk/internal/reflect/NativeMethodAccessorImpl.java:-2
invoke at jdk/internal/reflect/NativeMethodAccessorImpl.java:62
invoke at jdk/internal/reflect/DelegatingMethodAccessorImpl.java:43
invoke at java/lang/reflect/Method.java:566
invokeDirectWithExceptionHandling at org/jruby/javasupport/JavaMethod.java:456
invokeStaticDirect at org/jruby/javasupport/JavaMethod.java:368
invokeOther3:valueOf at -e:1
<main> at -e:1
run at -e:-1
invokeWithArguments at java/lang/invoke/MethodHandle.java:710
runScript at org/jruby/Ruby.java:1257
runNormally at org/jruby/Ruby.java:1176
runNormally at org/jruby/Ruby.java:1158
runNormally at org/jruby/Ruby.java:1194
runFromMain at org/jruby/Ruby.java:977
doRunFromMain at org/jruby/Main.java:400
internalRun at org/jruby/Main.java:292
run at org/jruby/Main.java:234
main at org/jruby/Main.java:206
~ ∴ ruby -e 'begin; p java.lang.Integer.valueOf("abc"); rescue StandardError => e; p e; p e.class; p e.class.ancestors; end'
java.lang.NumberFormatException: For input string: "abc"
Java::JavaLang::NumberFormatException
[Java::JavaLang::NumberFormatException, Java::JavaLang::IllegalArgumentException, Java::JavaLang::RuntimeException, Java::JavaLang::Exception, Java::JavaLang::Throwable, Java::JavaIo::Serializable, Java::JavaLang::Object, ConcreteJavaProxy, JavaProxy, JavaProxyMethods, Object, Kernel, BasicObject]
~ ∴ ruby -e 'begin; p java.lang.Integer.valueOf("abc"); rescue Exception => e; p e; p e.class; p e.class.ancestors; end'
java.lang.NumberFormatException: For input string: "abc"
Java::JavaLang::NumberFormatException
[Java::JavaLang::NumberFormatException, Java::JavaLang::IllegalArgumentException, Java::JavaLang::RuntimeException, Java::JavaLang::Exception, Java::JavaLang::Throwable, Java::JavaIo::Serializable, Java::JavaLang::Object, ConcreteJavaProxy, JavaProxy, JavaProxyMethods, Object, Kernel, BasicObject]
Reported by @jylamont in https://graalvm.slack.com/archives/CMY63522F/p1637250173107100
Like
rescue Java.type('org.foo.SomeException')
.rescue Java.type('org.postgresql.util.PSQLException')
should work but it does not currently.It's unclear if a lone
rescue
should rescue foreign exceptions.JRuby behavior seems to treat StandardError specially as an ad-hoc way to support lone
rescue
.I am not sure we want to follow that.
So all host exceptions seem to be considered StandardError or so, even though the ancestors do not reflect that.
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#exception-handling
Internal issue: GR-34933
The text was updated successfully, but these errors were encountered: