Mojo struct
Error
struct Error
This type represents an Error.
Fields
- data (
String): The message of the error.
Implemented traits
AnyType,
Boolable,
Copyable,
Defaultable,
ImplicitlyDestructible,
Movable,
Representable,
Stringable,
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:
__init__(out self)
Default constructor.
@implicit
__init__(out self, value: StringLiteral[value])
Construct an Error object with a given string literal.
Args:
- value (
StringLiteral): The error message.
@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 satisfyWritable.
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) -> Optional[String]
Returns the stack trace of the error, if available.
Returns:
Optional: An Optional[String] containing the stack trace if one was
collected, or None if stack trace collection was disabled
or unavailable.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!