Mojo struct
Error
This type represents an Error.
Fields
- data (
UnsafePointer[SIMD[uint8, 1], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): A pointer to the beginning of the string data being referenced. - loaded_length (
Int
): The length of the string being referenced. Error instances conditionally own their error message. To reduce the size of the error instance we use the sign bit of the length field to store the ownership value. When loaded_length is negative it indicates ownership and a free is executed in the destructor.
Implemented traits
AnyType
,
Boolable
,
CollectionElement
,
CollectionElementNew
,
Copyable
,
ExplicitlyCopyable
,
Formattable
,
Movable
,
Representable
,
Stringable
Methods
__init__
__init__(inout self: Self)
Default constructor.
__init__(inout self: Self, value: StringLiteral)
Construct an Error object with a given string literal.
Args:
- value (
StringLiteral
): The error message.
__init__(inout self: Self, src: String)
Construct an Error object with a given string.
Args:
- src (
String
): The error message.
__init__(inout self: Self, src: StringRef)
Construct an Error object with a given string ref.
Args:
- src (
StringRef
): The error message.
__init__(inout self: Self, *, other: Self)
Copy the object.
Args:
- other (
Self
): The value to copy.
__copyinit__
__copyinit__(inout self: Self, existing: Self)
Creates a deep copy of an existing error.
Args:
- existing (
Self
): The error to copy from.
__del__
__del__(owned self: Self)
Releases memory if allocated.
__bool__
__bool__(self: Self) -> Bool
Returns True if the error is set and false otherwise.
Returns:
True if the error object contains a value and False otherwise.
__str__
__str__(self: Self) -> String
Converts the Error to string representation.
Returns:
A String of the error message.
format_to
format_to(self: Self, inout writer: Formatter)
Formats this error to the provided formatter.
Args:
- writer (
Formatter
): The formatter to write to.
__repr__
__repr__(self: Self) -> String
Converts the Error to printable representation.
Returns:
A printable representation of the error message.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
😔 What went wrong?