Skip to content

Instantly share code, notes, and snippets.

@arielvalentin
Created August 5, 2014 03:20
Show Gist options
  • Save arielvalentin/c340ae45dd83af8fd9d9 to your computer and use it in GitHub Desktop.
Save arielvalentin/c340ae45dd83af8fd9d9 to your computer and use it in GitHub Desktop.
Sample code Throwable vs RubyException
# The following block logs java.lang.Throwable correctly: http://www.slf4j.org/api/org/slf4j/Logger.html#error(java.lang.String,%20java.lang.Throwable)
begin
Java::ComGoogleCommonBase::Preconditions.check_argument(false, "I don't like you")
rescue => e
logger = Java::OrgSlf4j::LoggerFactory.get_logger('logger')
logger.error("This works", e)
end
# However RubyException is not a throwable and treats it as a java.lang.Object: http://www.slf4j.org/api/org/slf4j/Logger.html#error(java.lang.String,%20java.lang.Object...)
begin
raise "error"
rescue => e
logger = Java::OrgSlf4j::LoggerFactory.get_logger('logger')
logger.error("This doesn't", e)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment