-
-
Notifications
You must be signed in to change notification settings - Fork 4
Error
Errors and exceptions in angle are tightly linked with the concept of optionally in variables:
The function parse string as int?
either returns an int or a typed error "missing int" !int
with associated (?todo) type format error or number to large etc
The result can be handled positively:
if result { print "we have a number %d" % result }
if no result { print "parse did not return a number" }
if result failed { print "we have an error %e" % result }
or
if result failed { print "we have an error %s" % result.error }
on error { print "we have an error %e" % error }
Just like in swift optionals can be unwrapped with tailing !
which throws if the variables value is missing or erroneous.
Note that no result
is true both for missing and erroneous objects, which might be sufficient for most control flow, otherwise one can distinguish with result == 0
== result null
result missing
result empty
and result failed