-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy patherror_lifecycle.rb
More file actions
49 lines (43 loc) · 1.31 KB
/
error_lifecycle.rb
File metadata and controls
49 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class MyStandardError < StandardError; end
class MyException< Exception; end
class ErrorLifeCycleTester
attr_reader :inner_attempted, :inner_else, :inner_rescue, :inner_ensure, :inner_ensure_has_time_to_finish, :outer_rescue, :outer_else, :outer_ensure, :outer_ensure_has_time_to_finish
def subject(error_to_raise, error_to_rescue)
@inner_attempted = nil
@inner_else = nil
@inner_rescue = nil
@inner_ensure = nil
@inner_ensure_has_time_to_finish = nil
@outer_rescue = nil
@outer_else = nil
@outer_ensure = nil
@outer_ensure_has_time_to_finish = nil
begin
Timeout.timeout(0.001, error_to_raise){
begin
@inner_attempted = true
nil while true
rescue error_to_rescue
@inner_rescue = true
else
@inner_else = true
ensure
@inner_ensure = true
t = Time.now; nil while Time.now < t+1
@inner_ensure_has_time_to_finish = true
end
}
rescue Exception
@outer_rescue = true
else
@outer_else = true
ensure
@outer_ensure = true
t = Time.now; nil while Time.now < t+1
@outer_ensure_has_time_to_finish = true
end
unless !!@outer_else ^ !!@outer_rescue
raise "something strange happened with the outer_rescue variables"
end
end
end