Created
May 21, 2013 22:59
-
-
Save b-studios/5623948 to your computer and use it in GitHub Desktop.
proceedable exceptions in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "continuation" | |
module Proceedable | |
class ProceedableException < Exception | |
def initialize(msg, cont) | |
super(msg) | |
@cont = cont | |
end | |
def proceed | |
@cont.call() | |
end | |
end | |
def throw(msg) | |
callcc {|cont| raise ProceedableException.new(msg, cont) } | |
end | |
end | |
include Proceedable | |
def a | |
throw "boom" | |
puts "after boom" | |
end | |
def b | |
a() | |
end | |
begin | |
b() | |
rescue ProceedableException => e | |
puts "caught #{e}" | |
e.proceed | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment