Skip to content
CryoCryo home
Stdlibcore

error

import std::core::error; · source

Every standard library error implements Error: it prints a message for a person through Display, a fuller form for a developer through Debug, and may name the error it was caused by. ErrorReport is the one owning carrier any error converts into, so a function that can fail in several unrelated ways can return them all as one type.

Types

Error

type trait Error : Display, Debug {
    source(&this) -> Option<virtual &Error>;
}

source is the error this one was caused by, if it keeps one; the default answers None. A wrapper error — one that adds context to a lower-level failure — overrides it to hand the inner error out as a trait object, so a reader can walk the whole chain.

Methods

source(&this) -> Option<virtual &Error>;

The error this one was caused by, if it keeps one. None by default.

Implementors

implement trait Error for struct DecodeError
std::encoding::error
implement trait Error for struct TomlError
std::encoding::toml::error
implement trait Error for struct YamlError
std::encoding::yaml::error
implement trait Error for struct ArgumentError
std::env::arguments
implement trait Error for struct IoError
std::fmt::display
implement trait Error for struct Utf8Error
std::fmt::display
implement trait Error for struct JsonError
std::fmt::display
implement trait Error for struct ValueDecodeError
std::fmt::display
implement<E> trait Error for enum FromTextError<E> where E: Error
std::fmt::display
implement trait Error for enum RandomError
std::fmt::display
implement trait Error for struct AllocationError
std::fmt::display
implement trait Error for struct ConversionError
std::fmt::display
implement trait Error for enum FormatError
std::fmt::display
implement trait Error for enum JoinError
std::future::executor
implement trait Error for struct LogSpecificationError
std::log::logger
implement trait Error for enum UrlError
std::net::address::url
implement<T> trait Error for struct SendError<T>
std::sync::channel
implement<T> trait Error for enum TrySendError<T>
std::sync::channel
implement trait Error for enum ReceiveError
std::sync::channel
implement trait Error for enum TryReceiveError
std::sync::channel
implement trait Error for enum ReceiveTimeoutError
std::sync::channel
implement trait Error for enum TestError
std::test::error
implement trait Error for enum SpawnError
std::thread
implement trait Error for struct DateTimeError
std::time::datetime

ErrorReport

type struct ErrorReport {
    private message: String;
    private causes:  Array<String>;
}

An error kept as text: its own message and the message of each error in its chain of sources, outermost first. Keeping the text rather than the error is what lets a report outlive the error it came from, and what lets errors of different types travel as one. Display prints the message and the causes joined by : ; Debug puts each cause on a line of its own, after caused by: .

Any Error converts into a report through From, so ? in a function returning Result<T, ErrorReport> passes on whatever error it meets:

import std::core::error::{ ErrorReport };
import std::collections::string::{ String };
import std::fs::{ File, Path };

function settings(path: Path) -> Result<String, ErrorReport> {
    const text: String = File::read_text(path)?;
    return Result::Ok(text);
}

A report is not an Error itself, which is what keeps its From impl and the identity From<T> for T from both applying to one type.

Constructors

static from_error<E>(error: &E) -> ErrorReport where E: Error;

The report of error: its Display text and that of each source.

Methods

message(&this) -> Str;

The error's own message.

causes(&this) -> implement Iterator<Str>;

The message of each error in the chain of sources, outermost first.

Trait implementations

implement<E> trait From<E> for struct ErrorReport where E: Error
implement trait Display for struct ErrorReport
implement trait Debug for struct ErrorReport

BoxedError

type struct BoxedError {
    private value:  mut u8*;
    private object: virtual &Error;
}

Any error, owned whole: the value of whatever type implements Error, moved to the heap and reached through its Error table. Any Error converts into one (BoxedError::new, or From), so ? in a function returning Result<T, BoxedError> passes on errors of any type, and the caller still holds each error itself, its source chain included, where ErrorReport keeps only text. It prints as the error does.

Constructors

static new<E>(error: E) -> BoxedError where E: Error;

error, moved into a carrier of its own.

Methods

error(&this) -> virtual &Error;

The error carried, through its Error table: its source chain, and its Display and Debug text.

Trait implementations

implement<E> trait From<E> for struct BoxedError where E: Error
implement trait Drop for struct BoxedError
implement trait Display for struct BoxedError
implement trait Debug for struct BoxedError