Created
March 24, 2010 09:59
-
-
Save vvs/342141 to your computer and use it in GitHub Desktop.
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
require 'java' | |
$CLASSPATH << "." | |
def foo | |
foo | |
end | |
begin | |
# These all work as expected: | |
# | |
# java.lang.Integer.decode('aaa') | |
# Java::Thrower::throwError | |
# Java::Thrower::throwOutOfMemoryError | |
# Java::Thrower::throwStackOverflow | |
# Java::Thrower::throwNPE | |
# These don't work with rescue Exception: | |
# | |
# foo # this causes stack overflow and exits JRuby: | |
# Error: Your application used more stack memory than the safety cap of 1024k. | |
# Can be rescued with rescue java.lang.StackOverflowError though. | |
# | |
# | |
# raise java.lang.NullPointerException.new("baaaa") # exits JRuby: | |
# NativeConstructorAccessorImpl.java:-2:in `newInstance0': java.lang.NullPointerException: baaaa | |
# from NativeConstructorAccessorImpl.java:39:in `newInstance' | |
# from DelegatingConstructorAccessorImpl.java:27:in `newInstance' | |
# from Constructor.java:513:in `newInstance' | |
# | |
# | |
# a = ''; 1000000.times {a << String.new('a'*10000)} # produces OOME | |
# Error: Your application used more memory than the safety cap of 500m. | |
rescue Exception => e | |
puts "Caught in Ruby: #{e.class} -- #{e}" | |
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
public class Thrower { | |
public static void throwError() { | |
System.err.println("About to throw Error"); | |
throw new UnknownError("Unknown Error"); | |
} | |
public static void throwOutOfMemoryError () { | |
System.err.println("About to throw OutOfMemoryError "); | |
throw new OutOfMemoryError ("No Memory Error"); | |
} | |
public static void throwNPE() { | |
System.err.println("About to throw NPE"); | |
throw new NullPointerException("NPE"); | |
} | |
public static void throwStackOverflow() { | |
throwStackOverflow(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment