Skip to content

Instantly share code, notes, and snippets.

@civitaspo
Created May 23, 2017 00:53
Show Gist options
  • Save civitaspo/415142e2d567ec5ff79827b35d50f9fb to your computer and use it in GitHub Desktop.
Save civitaspo/415142e2d567ec5ff79827b35d50f9fb to your computer and use it in GitHub Desktop.
require 'java'
class Error < Java::JavaLang::RuntimeException; end
class Error1 < Error; end
class Error2 < Error; end
class Error3 < Error; end
def err1
raise Error1.new("err")
end
def err2
begin
err1
rescue Error1 => e
raise Error2.new(e)
end
end
def err3
begin
err2
rescue Error2 => e
raise Error3.new(e)
end
end
def err
begin
err3
rescue => e
raise Error.new(e)
end
end
begin
err
rescue => e
$stderr.puts "e: {class:#{e.class},msg:#{e}}"
$stderr.puts "e.cause: {class:#{e.cause.class},msg:#{e.cause}}"
$stderr.puts "e.cause.cause: {class:#{e.cause.cause.class},msg:#{e.cause.cause}}"
$stderr.puts "e.cause.cause.cause: {class:#{e.cause.cause.cause.class},msg:#{e.cause.cause.cause}}"
end
e: {class:Error,msg:org.jruby.proxy.java.lang.RuntimeException$Proxy1: org.jruby.proxy.java.lang.RuntimeException$Proxy1: org.jruby.proxy.java.lang.RuntimeException$Proxy1: err}
e.cause: {class:Error3,msg:org.jruby.proxy.java.lang.RuntimeException$Proxy1: org.jruby.proxy.java.lang.RuntimeException$Proxy1: err}
e.cause.cause: {class:Error2,msg:org.jruby.proxy.java.lang.RuntimeException$Proxy1: err}
e.cause.cause.cause: {class:Error1,msg:err}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment