Module: Orientdb4r::ChainedError

Included in:
OrientdbError
Defined in:
lib/orientdb4r/chained_error.rb

Overview

This mixin extends an error to be able to track a chain of exceptions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



7
8
9
# File 'lib/orientdb4r/chained_error.rb', line 7

def cause
  @cause
end

Instance Method Details

#initialize(message = nil, cause = $!) ⇒ Object

Constructor.



11
12
13
14
15
# File 'lib/orientdb4r/chained_error.rb', line 11

def initialize message = nil, cause = $!
  super message unless message.nil?
  super $! if message.nil? and !cause.nil?
  @cause = cause
end

#set_backtrace(bt) ⇒ Object

Modification of original method Error#set_backtrace to descend the full depth of the exception chain.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/orientdb4r/chained_error.rb', line 20

def set_backtrace bt
  unless cause.nil?
    cause.backtrace.reverse.each do |line|
      if bt.last == line
        bt.pop
        next
      end
      break
    end
    bt.push "<<<CAUSED BY>>>: #{cause.class}: #{cause.message}"
    bt.concat cause.backtrace
  end
  super bt
end