require 'java'
java_import 'com.agiledeveloper.AJavaClass'

inst = AJavaClass.new

begin
  inst.someService do
    inst.someMethod()
  end
rescue => ex
  puts "Java layer did not handle the exception!"
  puts "The exception received was #{ex}"
  puts "The exception class was #{ex.class}"
end

puts "Let's try again...."

begin
  inst.someService do
    begin
      inst.someMethod()
    rescue NativeException => ex
      raise ex.cause if ex.cause.java_class.package.name.include? "com.agiledeveloper"
    end
  end
rescue => ex
  puts "Java layer did not handle the exception!"
  puts "The exception received was #{ex}"
  puts "The exception class was #{ex.class}"
end
