-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-33908] [GR-34933] Support foreign exceptions fully and stop trans…
…lating them to Ruby RuntimeError PullRequest: truffleruby/3203
- Loading branch information
Showing
42 changed files
with
725 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. This | ||
# code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
# redistribute it and/or modify it under the terms of the: | ||
# | ||
# Eclipse Public License version 2.0, or | ||
# GNU General Public License version 2, or | ||
# GNU Lesser General Public License version 2.1. | ||
|
||
require_relative '../../ruby/spec_helper' | ||
|
||
guard -> { !TruffleRuby.native? } do | ||
describe "Java exceptions" do | ||
it "can be rescued with Polyglot::ForeignException" do | ||
integer_class = Java.type("java.lang.Integer") | ||
|
||
-> { integer_class.valueOf("abc") }.should raise_error(Polyglot::ForeignException) | ||
end | ||
|
||
it "can be rescued with java.lang.NumberFormatException" do | ||
integer_class = Java.type("java.lang.Integer") | ||
number_format_exception = Java.type("java.lang.NumberFormatException") | ||
|
||
-> { integer_class.valueOf("abc") }.should raise_error(number_format_exception) | ||
end | ||
|
||
it "can be rescued with java.lang.RuntimeException" do | ||
integer_class = Java.type("java.lang.Integer") | ||
runtime_exception = Java.type("java.lang.RuntimeException") | ||
|
||
-> { integer_class.valueOf("abc") }.should raise_error(runtime_exception) | ||
end | ||
|
||
it "can be rescued with java.lang.Throwable" do | ||
integer_class = Java.type("java.lang.Integer") | ||
throwable = Java.type("java.lang.Throwable") | ||
|
||
-> { integer_class.valueOf("abc") }.should raise_error(throwable) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. This | ||
# code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
# redistribute it and/or modify it under the terms of the: | ||
# | ||
# Eclipse Public License version 2.0, or | ||
# GNU General Public License version 2, or | ||
# GNU Lesser General Public License version 2.1. | ||
|
||
require_relative '../../../ruby/spec_helper' | ||
|
||
describe "Polyglot::ForeignException" do | ||
before :each do | ||
@foreign = Truffle::Debug.foreign_exception("exception message") | ||
end | ||
|
||
it "supports #message" do | ||
@foreign.message.should == "exception message" | ||
end | ||
|
||
it "supports #cause" do | ||
@foreign.cause.should == nil | ||
end | ||
|
||
it "supports rescue Polyglot::ForeignException" do | ||
begin | ||
raise @foreign | ||
rescue Polyglot::ForeignException => e | ||
e.should.equal?(@foreign) | ||
end | ||
end | ||
|
||
it "supports rescue Object" do | ||
begin | ||
raise @foreign | ||
rescue Object => e | ||
e.should.equal?(@foreign) | ||
end | ||
end | ||
|
||
it "supports rescue class" do | ||
begin | ||
raise @foreign | ||
rescue @foreign.class => e | ||
e.should.equal?(@foreign) | ||
end | ||
end | ||
|
||
it "supports #raise" do | ||
-> { raise @foreign }.should raise_error(Polyglot::ForeignException) { |e| | ||
e.should.equal?(@foreign) | ||
} | ||
end | ||
|
||
it "supports #backtrace" do | ||
@foreign.backtrace.should.is_a?(Array) | ||
@foreign.backtrace.should_not.empty? | ||
@foreign.backtrace.each { |entry| entry.should.is_a?(String) } | ||
end | ||
|
||
it "supports #backtrace_locations" do | ||
@foreign.backtrace_locations.should.is_a?(Array) | ||
@foreign.backtrace_locations.should_not.empty? | ||
@foreign.backtrace_locations.each do |entry| | ||
entry.should.respond_to?(:absolute_path) | ||
entry.path.should.is_a?(String) | ||
entry.lineno.should.is_a?(Integer) | ||
entry.label.should.is_a?(String) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.