Mojo struct
StackTrace
struct StackTrace
Holds a stack trace captured at a specific location.
A StackTrace instance always contains a valid stack trace. Use the
collect_if_enabled() static method to conditionally capture a stack
trace, which returns None if stack trace collection is disabled or
unavailable.
Implemented traits
AnyType,
Copyable,
ImplicitlyDestructible,
Movable,
Writable
Methods
__init__
__init__(out self, *, unsafe_from_raw_pointer: UnsafePointer[UInt8, MutExternalOrigin])
Construct a StackTrace from a raw pointer to a C string.
Safety: The pointer must be valid and point to a null-terminated string. The caller transfers ownership to this StackTrace.
Args:
- unsafe_from_raw_pointer (
UnsafePointer): A pointer to a null-terminated C string containing the stack trace. The StackTrace takes ownership.
__init__(out self, *, copy: Self)
Copy constructor - copies the stack trace string.
Args:
- copy (
Self): The existing StackTrace to copy from.
__init__(out self, *, deinit take: Self)
Move constructor.
Args:
- take (
Self): The existing StackTrace to move from.
collect_if_enabled
static collect_if_enabled(depth: Int = 0) -> Optional[StackTrace]
Collect a stack trace if enabled by environment variable.
This method checks the MOJO_ENABLE_STACK_TRACE_ON_ERROR environment
variable and collects a stack trace only if it is enabled. Returns
None if stack traces are disabled, on GPU, or if collection fails.
Args:
- depth (
Int): The maximum depth of the stack trace to collect. Whendepthis zero, the entire stack trace is collected. Whendepthis negative, no stack trace is collected.
Returns:
Optional: An Optional[StackTrace] containing the stack trace if collection
succeeded, or None if disabled or unavailable.
write_to
write_to(self, mut writer: T)
Writes the StackTrace to the provided Writer.
Args:
- writer (
T): The object to write to.
write_repr_to
write_repr_to(self, mut writer: T)
Writes the StackTrace to the provided Writer in repr format.
Args:
- writer (
T): The object to write to.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!