salmanahmad / dog

The Dog Programming Language
http://www.dog-lang.org
Apache License 2.0
0 stars 0 forks source link

Exception Handling #60

Open salmanahmad opened 11 years ago

salmanahmad commented 11 years ago

General syntax:

do
  throw 3.14159 # Can throw any value.
catch error
  // Only one catch block. If you want to dispatch based on the type of the exception, implement it yourself.

  throw // Throw without a value will re-throw the current exception
ensure
  // Always runs  
end

The catch and ensure can be attached to any do block, even the blocks that represent control structures and functions:

define returns_pi do
  throw 3.14159
catch error
  i = error
ensure
  return i
end

In terms of implementation, the Signal class should be augmented to have an error field that will get propagated up until it is caught.