Skip to main content

Mojo struct

Error

struct Error

This type represents an Error.

Fields

  • data (String): The message of the error.
  • stack_trace (StackTrace): The stack trace of the error. By default the stack trace is not collected for the Error, unless user sets the stack_trace_depth parameter to value >= 0.

Implemented traits

AnyType, Boolable, Copyable, Defaultable, ImplicitlyCopyable, Movable, Representable, Stringable, UnknownDestructibility, Writable

comptime members

__copyinit__is_trivial

comptime __copyinit__is_trivial = False

__del__is_trivial

comptime __del__is_trivial = False

__moveinit__is_trivial

comptime __moveinit__is_trivial = False

Methods

__init__

@implicit __init__(out self, var value: String, *, depth: Int = -1)

Construct an Error object with a given String.

Args:

  • value (String): The error message.
  • depth (Int): The depth of the stack trace to collect.

__init__(out self)

Default constructor.

@implicit __init__(out self, value: StringLiteral[value])

Construct an Error object with a given string literal.

Args:

@implicit __init__(out self, arg: T)

Construct an Error from a Writable argument.

Args:

  • arg (T): A Writable argument.

__init__[*Ts: Writable](out self, *args: *Ts)

Construct an Error by concatenating a sequence of Writable arguments.

Parameters:

  • *Ts (Writable): The types of the arguments to format. Each type must be satisfy Writable.

Args:

  • *args (*Ts): A sequence of Writable arguments.

__bool__

__bool__(self) -> Bool

Returns True if the error is set and false otherwise.

Returns:

Bool: True if the error object contains a value and False otherwise.

__str__

__str__(self) -> String

Converts the Error to string representation.

Returns:

String: A String of the error message.

write_to

write_to(self, mut writer: T)

Formats this error to the provided Writer.

Args:

  • writer (T): The object to write to.

__repr__

__repr__(self) -> String

Converts the Error to printable representation.

Returns:

String: A printable representation of the error message.

get_stack_trace

get_stack_trace(self) -> StackTrace

Returns the stack trace of the error.

Returns:

StackTrace: The stringable stack trace of the error.

Was this page helpful?