Import std.core.error
Error
class
Public Class Error
The Class every error extends. Its first fields are Message, Cause, and Place, in that order, which the runtime reads and writes: Throw sets Place, unless the error has one from an earlier Throw, and top-level code that lets an error out shows all three, and its Cause's.
Examples
Function Age(text: String): Int Throws ArgumentError
Local age = Int.Parse(text)
If age == Null
Throw ArgumentError(ArgumentErrorKind.INVALID, "'{text}' isn't an age", "age")
End If
Return age
End Function
Local error = ExpectThrows<ArgumentError>(Age("old"))
Expect(error?.Kind == ArgumentErrorKind.INVALID)
Expect(error?.Message == "'old' isn't an age")
Expect(error?.Name == "age")
// An error can say what it comes from.
Local wrapped = Error("couldn't load the level", IOError(IOErrorKind.NOT_FOUND, "no such file"))
Expect(wrapped.Cause?.Message == "no such file")-
What went wrong, for people to read.
-
The error this one comes from, as when code that catches one throws its own.
-
Where it was first thrown.
-
Makes an error that says
message, fromcause, if it has one.
Report an issue with this page or with FutureBlitz on GitHub.