Fix dynamic rescue on Java exceptions (issue #1598)

For extended description see issue #1598.

Please check my code, I'm not familiar with the jruby codebase. This fix happens to work for me though =)