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
443
444
445
446
447
448
449
450
451
452
453
|
# File 'lib/cond.rb', line 401
def raise(*args)
if Cond.handlers_stack.last.empty?
Cond.original_raise(*args)
else
last_exception, current_handler = Cond.exception_stack.last
exception = (
if last_exception and args.empty?
last_exception
else
begin
Cond.original_raise(*args)
rescue Exception => e
e
end
end
)
if current_handler
handler = loop {
Cond.reraise_count += 1
handlers = Cond.handlers_stack[-1 - Cond.reraise_count]
if handlers.nil?
break nil
end
found = Cond.find_handler_from(handlers, exception.class)
if found and found != current_handler
break found
end
}
if handler
handler.call(exception)
else
Cond.reraise_count = 0
Cond.original_raise(exception)
end
else
Cond.reraise_count = 0
handler = Cond.find_handler(exception.class)
if handler
Cond.exception_stack.push([exception, handler])
begin
handler.call(exception)
ensure
Cond.exception_stack.pop
end
else
Cond.original_raise(exception)
end
end
end
end
|