File: eh.rb

package info (click to toggle)
dlr-languages 20090805%2Bgit.e6b28d27%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 51,484 kB
  • ctags: 59,257
  • sloc: cs: 298,829; ruby: 159,643; xml: 19,872; python: 2,820; yacc: 1,960; makefile: 96; sh: 65
file content (442 lines) | stat: -rw-r--r-- 8,362 bytes parent folder | download
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
def dumpex e
    # this will modify the class name as well in MRI (bug)
    #if e.message.length > 0 then
    #    e.message[0] = 'X'                    
    #end    
    
    puts "inspect: #{e.inspect.inspect}"
    puts "class: #{e.class.inspect}"
    puts "message: #{e.message.inspect}"
    puts "to_s: #{e.to_s.inspect}"
    puts
end

def test0
    puts '> IOError.new("foo")'
    dumpex(IOError.new("foo"))
    
    puts '> IOError.new'
    dumpex(IOError.new)
    
    puts '> IOError.new(nil)'
    dumpex(IOError.new(nil))
    
    puts '> IOError.new("")'
    dumpex(IOError.new(""))
    
    puts '> Exception.new'
    dumpex(Exception.new)
    puts
end

def test1
    $! = IOError.new "1"                    
    test1_helper
    puts "E: #{$!.inspect}"                                                         # 7
end

def test1_helper
    begin
        $! = IOError.new "2"                
        begin                                   # t1 = 2 (have rescue)
            $! = IOError.new "3"            
            begin
                begin
                    raise IOError.new("4")      
                ensure                          # t2 = 4                    
                    puts "A: #{$!.inspect}"                                     # 4
                    $! = IOError.new "8"        
                end                             # $! = t2
            ensure                              # t3 = $!
                puts "G: #{$!.inspect}"                                         # 4
                $! = IOError.new "10"            
            end                                 # $! = t3
        rescue                                  # $! = 4
            puts "B: #{$!.inspect}"                                             # 4
            $! = IOError.new "5"            
        ensure                                  # $! = t4 = 2
            puts "C: #{$!.inspect}"                                             # 2
            $! = IOError.new "6"            
        end                                     # $! = t4
        puts "F: #{$!.inspect}"                                                 # 2
        $! = IOError.new "8"            
    ensure                                      # t5 = 8
        puts "D: #{$!.inspect}"                                                 # 8
        $! = IOError.new "7"                
        return
    end                                         # $! = t5 (skipped by return)    
end

def test2
    $! = IOError.new "1"                    
    begin
        $! = IOError.new "2"                
        begin
            $! = IOError.new "3"            
            puts $!.inspect
        end
        puts $!.inspect
   end
   puts $!.inspect
end

def test3
    puts $!
    $! = IOError.new "1"                    
    begin
        puts $!
        $! = IOError.new "2"                
        begin
            puts $!
            $! = IOError.new "3"            
            puts $!
        ensure
            puts $!
        end
        puts $!
   ensure
        puts $!
   end
   puts $!
end

def test4
    puts "A:#{$!.inspect}"
    $! = IOError.new "1"                    
    begin
        puts "B:#{$!.inspect}"
        $! = IOError.new "2"                
        begin
            puts "C:#{$!.inspect}"
            $! = IOError.new "3"            
            puts "D:#{$!.inspect}"
        rescue
        ensure
            puts "E:#{$!.inspect}"
        end
        puts "F:#{$!.inspect}"
   rescue
        puts "G:#{$!.inspect}"
   end
   puts "H:#{$!.inspect}"
end

def test5
    g
    puts "H:#{$!.inspect}"
end

def g
    f { return }
end

def f
    $! = IOError.new "1"
    puts "A:#{$!.inspect}"
    while (true) do
        begin
            puts "C:#{$!.inspect}"
            $! = IOError.new "3"
            puts "D:#{$!.inspect}"
        rescue
        ensure
            puts "G:#{$!.inspect}"
            yield
        end
    end    
    puts "H:#{$!.inspect}"
end

def test6
    r = true
    $! = IOError.new "1"
    puts "A:#{$!.inspect}"
    begin
        puts "C:#{$!.inspect}"
        $! = IOError.new "3"
        puts "D:#{$!.inspect}"
        raise
    rescue
        puts "E:#{$!.inspect}"
        if r then
            r = false
            puts 'retry'
            retry
        end    
    else
        puts "ELSE:#{$!.inspect}"
    ensure
        puts "G:#{$!.inspect}"
    end
    puts "H:#{$!.inspect}"
end

def test7
    begin
        begin
            raise IOError.new("1")
        ensure
            puts $!.inspect
        end
    rescue
        puts $!.inspect
    end
end

def test8
    $! = IOError.new "1"
    begin
        puts $!.inspect
        $! = IOError.new "2"
        puts $!.inspect
    else
        puts "X", $!.inspect
    end
    puts $!.inspect
end

def test9
    $! = IOError.new "1"
    begin
        puts $!.inspect                #1
        $! = IOError.new "2"       
        puts $!.inspect                #2
    rescue
    else
        puts $!.inspect                #1
    end 
    puts $!.inspect                    #1
end

def test10
    $! = IOError.new "1"
    begin
    rescue
    else
        puts $!.inspect
    end
    puts $!.inspect
end

def test11
    $! = IOError.new "1"
    begin
    rescue
    ensure
        puts $!.inspect
    end
    puts $!.inspect
end

def test12
    $! = IOError.new "1"
    begin
    rescue
    else
        puts $!.inspect
    ensure
        puts $!.inspect
    end
    puts $!.inspect
end

def test13
    test13_helper
rescue
end

def test13_helper
    begin
        $! = IOError.new "1"
        begin
            puts "A: #{$!.inspect}"     
            raise IOError.new("4")      
        ensure                          
            puts "B: #{$!.inspect}"     
            $! = IOError.new "8"        
        end
    ensure
        puts "C: #{$!.inspect}"     
    end    
end

def test14
    $! = IOError.new "1"
    test14_helper
end

def test14_helper
    begin
        puts "A: #{$!.inspect}"     
        raise IOError.new("4")      
    ensure                          
        puts "B: #{$!.inspect}"     
        return                      # exception swallowed
    end
end

def test15
    $! = IOError.new "1"
    begin
        begin
            puts "A: #{$!.inspect}"     
            raise IOError.new("4")      
        ensure                          
            puts "B: #{$!.inspect}"     
            $! = IOError.new("5")
        end
    rescue
        puts "C: #{$!.inspect}"     
    end    
end

def test16
    $! = IOError.new "1"
    test16_helper
    puts "D: #{$!.inspect}"     
end

def test16_helper
    begin
        puts "A: #{$!.inspect}"     
    rescue
    else
        puts "B: #{$!.inspect}"     
        $! = IOError.new "2"
        raise IOError.new("3")
    ensure                          
        puts "C: #{$!.inspect}"     
        $! = IOError.new("5")
        return
    end
end

def test17
    $! = IOError.new "1"
    test17_helper
    puts "D: #{$!.inspect}"     
end

def test17_helper
    begin
        puts "A: #{$!.inspect}"     
    else
        puts "B: #{$!.inspect}"     
        $! = IOError.new "2"
        raise IOError.new("3")
    ensure                          
        puts "C: #{$!.inspect}"     
        $! = IOError.new("5")
        return
    end
end

def test18
	begin
		test18_helper
	rescue
		puts "C: #{$!.inspect}"     
	end
end

def test18_helper
	begin
        raise IOError.new("1")
    rescue (raise IOError.new("2"))
		puts "A: #{$!.inspect}"     
        raise IOError.new("3")
    end
    puts "B: #{$!.inspect}"     
end

def test19
	$! = IOError.new "1"
    begin
    else
        $! = IOError.new "2"
    ensure
		$! = IOError.new "3"
    end
    puts $!.inspect   #2
end


$! = nil
puts 'test0'
test0

$! = nil
puts 'test1'
test1

$! = nil
puts 'test2'
test2

$! = nil
puts 'test3'
test3

$! = nil
puts 'test4'
test4

$! = nil
puts 'test5'
test5

$! = nil
puts 'test6'
test6

$! = nil
puts 'test7'
test7

$! = nil
puts 'test8'
test8

$! = nil
puts 'test9'
test9

$! = nil
puts 'test10'
test10

$! = nil
puts 'test11'
test11

$! = nil
puts 'test12'
test12

$! = nil
puts 'test13'
test13

$! = nil
puts 'test14'
test14

$! = nil
puts 'test15'
test15

$! = nil
puts 'test16'
test16

$! = nil
puts 'test17'
test17

$! = nil
puts 'test18'
test18

$! = nil
puts 'test19'
test19