Skip to content

Instantly share code, notes, and snippets.

@banister
Created June 3, 2011 02:25
Show Gist options
  • Save banister/1005741 to your computer and use it in GitHub Desktop.
Save banister/1005741 to your computer and use it in GitHub Desktop.
manveru's nifty restartable exceptions
require 'continuation'
class RestartableError < StandardError
attr_accessor :cc
def self.call(msg)
instance = new(msg)
returning = true
callcc{|c| instance.cc = c }
returning = !returning
raise instance unless returning
end
end
class Foo
def a
puts "everything fine a"
RestartableError.call("omg!")
puts "everything fine b"
end
end
begin
Foo.new.a
rescue RestartableError => ex
p ex
p ex.cc.call
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment