Skip to content

Instantly share code, notes, and snippets.

@b-studios
Created May 21, 2013 22:59
Show Gist options
  • Save b-studios/5623948 to your computer and use it in GitHub Desktop.
Save b-studios/5623948 to your computer and use it in GitHub Desktop.
proceedable exceptions in ruby
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