-
Notifications
You must be signed in to change notification settings - Fork 1
Exception
Justin Mann edited this page Nov 11, 2017
·
2 revisions
Throw takes a single parameter which is the exception. The exception can be any value type: function, int, float, string.
throw("hi")
Exceptions can only be caught after a function block. There is no finally logic and only one catch handle is allowed. The exception can be accessed by using the lambda default parameter helper "_".
func() {
throw("argh")
12
} catch {
str: _ as string
if str == "argh" {
13
} else {
throw _
}
}
If you have a completely unrecoverable error like a stack overflow exception, then you kill the program with "die". This will allow the default stack cleanup code to execute, but cannot be caught.
func() {
die("no recovery possible")
} catch {
// This is not going to be used, you cannot catch "die"
}