Class: Roby::ExecutionException
- Includes:
- DRoby::V5::ExecutionExceptionDumper
- Defined in:
- lib/roby/exceptions.rb,
lib/roby/droby/enable.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
-
#exception ⇒ Object
readonly
The exception object.
-
#generator ⇒ Object
readonly
The origin EventGenerator if there is one.
-
#handled ⇒ Object
If this specific exception has been marked has handled.
-
#origin ⇒ Object
readonly
The object from which the exception originates.
-
#trace ⇒ Relations::BidirectionalDirectedAdjacencyGraph
readonly
The trace of how this exception has been propagated in the plan so far.
Instance Method Summary collapse
-
#each_involved_task(&block) ⇒ Object
Enumerates all tasks that are involved in this exception (either origin or in the trace).
-
#fatal? ⇒ Boolean
If true, the underlying exception is a fatal error, i.e.
-
#fork ⇒ Object
Create a sibling from this exception.
-
#handled? ⇒ Boolean
If this exception has been marked as handled.
-
#initialize(exception) ⇒ ExecutionException
constructor
Creates a new execution exception object with the specified source If
source
is nil, tries to guess the source fromexception
: ifexception
responds to #task or #generator we use either #task or call #generator.task. - #initialize_copy(from) ⇒ Object
- #involved_task?(task) ⇒ Boolean
-
#merge(sibling) ⇒ Object
Merges
sibling
into this object. -
#originates_from?(object) ⇒ Boolean
True if this exception originates from the given task or generator.
- #pretty_print(pp) ⇒ Object
- #propagate(from, to) ⇒ Object
-
#propagation_leafs ⇒ Object
The last object(s) that handled the exception.
-
#reset_trace ⇒ Object
Resets the trace to [origin].
- #to_execution_exception ⇒ Object
- #to_s ⇒ Object
Methods included from DRoby::V5::ExecutionExceptionDumper
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
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/roby/exceptions.rb', line 105 def initialize(exception) @exception = exception @trace = Relations::BidirectionalDirectedAdjacencyGraph.new if task = exception.failed_task @origin = task @trace.add_vertex(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
#exception ⇒ Object (readonly)
The exception object
68 69 70 |
# File 'lib/roby/exceptions.rb', line 68 def exception @exception end |
#generator ⇒ Object (readonly)
The origin EventGenerator if there is one
66 67 68 |
# File 'lib/roby/exceptions.rb', line 66 def generator @generator end |
#handled ⇒ Object
If this specific exception has been marked has handled
71 72 73 |
# File 'lib/roby/exceptions.rb', line 71 def handled @handled end |
#origin ⇒ Object (readonly)
The object from which the exception originates
57 58 59 |
# File 'lib/roby/exceptions.rb', line 57 def origin @origin end |
#trace ⇒ Relations::BidirectionalDirectedAdjacencyGraph (readonly)
The trace of how this exception has been propagated in the plan so far
48 49 50 |
# File 'lib/roby/exceptions.rb', line 48 def trace @trace end |
Instance Method Details
#each_involved_task(&block) ⇒ Object
Enumerates all tasks that are involved in this exception (either origin or in the trace)
80 81 82 83 84 |
# File 'lib/roby/exceptions.rb', line 80 def each_involved_task(&block) return enum_for(__method__) unless block_given? trace.each_vertex(&block) end |
#fatal? ⇒ Boolean
If true, the underlying exception is a fatal error, i.e. should cause parent tasks to be stopped if unhandled.
61 62 63 |
# File 'lib/roby/exceptions.rb', line 61 def fatal? exception.fatal? end |
#fork ⇒ Object
Create a sibling from this exception
123 124 125 |
# File 'lib/roby/exceptions.rb', line 123 def fork dup end |
#handled? ⇒ Boolean
If this exception has been marked as handled
74 75 76 |
# File 'lib/roby/exceptions.rb', line 74 def handled? handled end |
#initialize_copy(from) ⇒ Object
142 143 144 145 |
# File 'lib/roby/exceptions.rb', line 142 def initialize_copy(from) super @trace = from.trace.dup end |
#involved_task?(task) ⇒ Boolean
86 87 88 |
# File 'lib/roby/exceptions.rb', line 86 def involved_task?(task) trace.has_vertex?(task) end |
#merge(sibling) ⇒ Object
Merges sibling
into this object
137 138 139 140 |
# File 'lib/roby/exceptions.rb', line 137 def merge(sibling) @trace.merge(sibling.trace) self end |
#originates_from?(object) ⇒ Boolean
True if this exception originates from the given task or generator
97 98 99 |
# File 'lib/roby/exceptions.rb', line 97 def originates_from?(object) [generator, origin].include?(object) end |
#pretty_print(pp) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/roby/exceptions.rb', line 155 def pretty_print(pp) pp.text "from #{origin} with trace" pp.nest(2) do pp.nest(2) do trace.each_edge do |a, b, _| pp.breakable pp.text "#{a} => #{b}" end end pp.breakable pp.text "Exception:" pp.nest(2) do pp.breakable exception.pretty_print(pp) end end end |
#propagate(from, to) ⇒ Object
127 128 129 |
# File 'lib/roby/exceptions.rb', line 127 def propagate(from, to) trace.add_edge(from, to) end |
#propagation_leafs ⇒ Object
The last object(s) that handled the exception. This is either a single object or an array
52 53 54 |
# File 'lib/roby/exceptions.rb', line 52 def propagation_leafs trace.each_vertex.find_all { |v| trace.leaf?(v) } end |
#reset_trace ⇒ Object
Resets the trace to [origin]
91 92 93 94 |
# File 'lib/roby/exceptions.rb', line 91 def reset_trace @trace = Relations::BidirectionalDirectedAdjacencyGraph.new @trace.add_vertex(@origin) end |
#to_execution_exception ⇒ Object
147 148 149 |
# File 'lib/roby/exceptions.rb', line 147 def to_execution_exception self end |
#to_s ⇒ Object
151 152 153 |
# File 'lib/roby/exceptions.rb', line 151 def to_s PP.pp(self, "".dup) end |