Exceptions
Exceptions in Citron are pretty much the same as all other languages; they occur when exceptional things occur!
Basic Errors
Errors can be generated with Block::'error:'
The interpreter itself also can generate errors for unkown keys, etc.
⠕ Pen writenl: 'This will make an exception!'. #Note that the method name is spelled incorrectly
#=> Exception: Unknown method Object::'writenl:' was called
⠕ pen writeln: 'This will do that too'. #Misspelled 'Pen'
#=> Exception: Key not found: pen
Raising and Handling Exceptions
All the exceptions generated by the interpreter are of type String, however a facility is provided to use and catch exceptions of different types:
{
thisBlock error: Nil.
} catch: {:e Pen writeln: 'Nil!'.} type: Nil,
run.
#=> Nil!
There is not much more involved, just note that exceptions are used only when no other way of handling the current situation exists.
For instance, a miss on a map lookup is not an exceptional thing, it will simply return Nil.