Skip to content
FutureBlitz

    Install

    Import std.core.error

    Error

    std.core.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")

    std/core/error.fb, line 66

    • Public Field Message: String field #

      What went wrong, for people to read.

    • Public Field Cause: Error? field #

      The error this one comes from, as when code that catches one throws its own.

    • Public ReadOnly Field Place: Place field #

      Where it was first thrown.

    • Public New(message: String = "", cause: Error? = Null) constructor #

      Makes an error that says message, from cause, if it has one.

    Report an issue with this page or with FutureBlitz on GitHub.