Class: Roby::ExecutionException

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/exceptions.rb

Overview

ExecutionException objects are used during the exception handling stage to keep information about the propagation.

When a propagation fork is found (for instance, a task with two parents), two or more siblings are created with #fork. If at some point two siblings are to be handled by the same task, coming for instance from two different children, then they are merged with #merge to from one single ExecutionException object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ ExecutionException

Creates a new execution exception object with the specified source If source is nil, tries to guess the source from exception: if exception responds to #task or #generator we use either #task or call #generator.task



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/roby/exceptions.rb', line 66

def initialize(exception)
    @exception = exception
    @trace = Array.new
    @siblings = [self]

    if task = exception.failed_task
  @trace << exception.failed_task
    end
    if generator = exception.failed_generator
  @generator = exception.failed_generator
    end

    if !task && !generator
  raise ArgumentError, "invalid exception specification: cannot get the exception source"
    end
end

Instance Attribute Details

#exceptionObject (readonly)

The exception object



47
48
49
# File 'lib/roby/exceptions.rb', line 47

def exception
  @exception
end

#generatorObject (readonly)

The origin EventGenerator if there is one



45
46
47
# File 'lib/roby/exceptions.rb', line 45

def generator
  @generator
end

#handledObject

If this specific exception has been marked has handled



50
51
52
# File 'lib/roby/exceptions.rb', line 50

def handled
  @handled
end

#siblingsObject (readonly)

The exception siblings (the ExecutionException objects that come from the same exception object)



43
44
45
# File 'lib/roby/exceptions.rb', line 43

def siblings
  @siblings
end

#traceObject (readonly)

The propagation trace. Because of forks and merges, this should be a graph. We don’t use graph properties (at least not yet), so consider this as the list of objects which did not handle the exeption. Only trace.last and trace.first have a definite meaning: the former is the last object(s) that handled the propagation and the latter is the object from which the exception originated. They can be accessed through #task and #origin.



34
35
36
# File 'lib/roby/exceptions.rb', line 34

def trace
  @trace
end

Instance Method Details

#each_siblingObject

Enumerates this exception’s siblings



56
57
58
59
60
# File 'lib/roby/exceptions.rb', line 56

def each_sibling
    for e in siblings
  yield(e) unless e == self
    end
end

#forkObject

Create a sibling from this exception



84
85
86
87
88
# File 'lib/roby/exceptions.rb', line 84

def fork
    sibling = dup
    self.siblings << sibling
    sibling
end

#handled?Boolean

If this exception or one of its siblings has been marked as handled



52
53
54
# File 'lib/roby/exceptions.rb', line 52

def handled?
    siblings.find { |s| s.handled }
end

#initialize_copy(from) ⇒ Object



105
106
107
108
# File 'lib/roby/exceptions.rb', line 105

def initialize_copy(from)
    super
    @trace = from.trace.dup
end

#merge(sibling) ⇒ Object

Merges sibling into this object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/roby/exceptions.rb', line 91

def merge(sibling)
    siblings.delete(sibling)

    topstack   = trace.pop
    s_topstack = sibling.trace.pop

    origin     = trace.shift
    s_origin   = sibling.trace.shift
    origin     = origin || s_origin || topstack

    new_top    = *(Array[*topstack] | Array[*s_topstack])
    @trace = [origin] + (trace | sibling.trace) << new_top
end

#originObject

The object from which the exception originates



39
# File 'lib/roby/exceptions.rb', line 39

def origin; trace.first end

#taskObject

The last object(s) that handled the exception. This is either a single object or an array



37
# File 'lib/roby/exceptions.rb', line 37

def task; trace.last end