Sha256: caaecaff5f7650ff5544d5af5e7365300396b4a3e3679d69b6d30b315ad5feb6
Contents?: true
Size: 916 Bytes
Versions: 31
Compression:
Stored size: 916 Bytes
Contents
# == NestedError # # An exception class that records the cause of another error. Useful when you # need to raise a general kind of error, yet still be able to determine the # underlying cause. # # Example: # # class MyGeneralError < NestedError; end # # begin # begin # # Cause a specific error # 1/0 # Divide by zero error # rescue Exception => e # # Wrap the specific error in a general, nested error # raise MyGeneralError("Something bad happened!", e) # end # rescue MyGeneralError => e # # Intercept the nested error and inspect the cause # puts e.message # => "Something bad happened!" # puts e.cause.message # => "divided by 0" # end class NestedError < StandardError attr_accessor :cause # Create a NestedObject with a +message+ String and a +cause+ Exception. def initialize(message, cause) self.cause = cause super(message) end end
Version data entries
31 entries across 31 versions & 2 rubygems