-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathraise.rb
More file actions
204 lines (184 loc) · 2.37 KB
/
raise.rb
File metadata and controls
204 lines (184 loc) · 2.37 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
class ExceptionA < Exception
end
class ExceptionB < Exception
end
def m1 x
if x > 2
raise "x > 2"
end
puts "x <= 2"
end
def m2 b
begin
if b
raise ExceptionA
end
rescue ExceptionA
puts "Rescued"
end
puts "End m2"
end
def m3 b
begin
if b
raise ExceptionA
end
rescue
puts "Rescued"
end
puts "End m3"
end
def m4 b
begin
if b
raise ExceptionA
end
rescue => e
puts "Rescued {e}"
end
puts "End m4"
end
def m5 b
begin
if b
raise ExceptionA
end
rescue => e
end
puts "End m5"
end
def m6 b
begin
if b
raise ExceptionA
end
rescue ExceptionA, ExceptionB => e
puts "Rescued {e}"
end
puts "End m6"
end
def m7 x
if x > 2
raise "x > 2"
elsif x < 0
return "x < 0"
end
puts "0 <= x <= 2"
ensure
puts "ensure"
end
def m8 x
puts "Begin m8"
begin
if x > 2
raise "x > 2"
elsif x < 0
return "x < 0"
end
puts "0 <= x <= 2"
ensure
puts "ensure"
end
puts "End m8"
end
def m9(x, b1, b2)
puts "Begin m9"
begin
if x > 2
raise "x > 2"
elsif x < 0
return "x < 0"
end
puts "0 <= x <= 2"
ensure
puts "outer ensure"
begin
if b1
raise "b1 is true"
end
ensure
puts "inner ensure"
end
end
puts "End m9"
ensure
puts "method ensure"
if b2
raise "b2 is true"
end
end
def m10(p = (raise "Exception"))
rescue
puts "Will not get executed if p is not supplied"
ensure
puts "Will not get executed if p is not supplied"
end
def m11 b
begin
if b
raise ExceptionA
end
rescue ExceptionA
rescue ExceptionB
puts "ExceptionB"
ensure
puts "Ensure"
end
puts "End m11"
end
def m12 b
if b
raise ""
end
ensure
return 3
end
def m13
ensure
end
def m14 element
element.each { |elem| raise "" if element.nil? }
end
def m15
foo do
bar ->(x) do
raise "" unless x
end
end
end
class C
def self.m()
raise ""
end
end
def m16(b1, b2)
begin
if b1 || b2 == true
return 1
else
return 2
end
rescue ExceptionA
return 3
end
end
def m17(b1, b2)
begin
raise ExceptionA if b1
rescue ExceptionA
if b2
b1 = false
retry
end
end
end
def m18(b2)
b1 = true
begin
raise ExceptionA if b1
rescue ExceptionA
if b2
b1 = false
end
end
end