Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Saturday 10 May 2014

Enhanced exception handling in ruby 2.1.0

This one was promoted by headius (Charles Nutter), so guaranteed to work with jruby-9000? Get access to the cause of the original exception, when re-thrown.
class ExceptionalClass
  def exceptional_method
    cause = nil
    begin
      raise "Boom!" # RuntimeError raised
    rescue => e
      raise StandardError, "Ka-pow!"
    end
  end
end

def setup
  size 500, 120
  background 50, 50, 200
  f = createFont("Arial", 16, true)
  text_font(f, 16)
  fill(255, 0, 0)
  begin
    ExceptionalClass.new.exceptional_method
  rescue Exception => e
    exception = "Caught Exception: #{e.message} [#{e.class}]"
    cause = "Caused by : #{e.cause.message} [#{e.cause.class}]"
    text(exception, 20, 30)
    fill(255, 255, 0)
    text(cause, 20, 60)
  end
end


No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2