Skip to content
CShift0.32

Error<T>

Struct · built-in type

struct Error<T>

A value or an error: the result of something that can fail.

Error<int> Parse(string s) { ... return error("not a number"); }
switch (Parse(text))
{
case int n: Console.WriteLine(n); break;
case error e: Console.WriteLine(e.Message); break;
}
int n = try Parse(text); // passes an error on to the caller

error("message") or error("message", code) makes the error; Error<void> is a result without a value. With an error enum the codes are typed: IoError<string> is Error<string, IoError> (IoError). See the language guide (error handling).

Name Description
Message The message of the error.
Code The code of the error (0 if none was given; the value of the error enum for a typed result).
string Message

The message of the error.

int Code

The code of the error (0 if none was given; the value of the error enum for a typed result).