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

Version Path
automate-it-0.9.2 lib/nested_error.rb
automate-it-0.9.1 lib/nested_error.rb
automate-it-0.9.0 lib/nested_error.rb
automateit-0.70923 lib/nested_error.rb
automateit-0.70928 lib/nested_error.rb
automateit-0.70930 lib/nested_error.rb
automateit-0.71003 lib/nested_error.rb
automateit-0.71006 lib/nested_error.rb
automateit-0.71012 lib/nested_error.rb
automateit-0.71021 lib/nested_error.rb
automateit-0.71030 lib/nested_error.rb
automateit-0.71031.2 lib/nested_error.rb
automateit-0.71031.1 lib/nested_error.rb
automateit-0.71017 lib/nested_error.rb
automateit-0.71101.1 lib/nested_error.rb
automateit-0.71102 lib/nested_error.rb
automateit-0.71103 lib/nested_error.rb
automateit-0.71101 lib/nested_error.rb
automateit-0.71031 lib/nested_error.rb
automateit-0.71101.2 lib/nested_error.rb