defaultTraceHandler

Get the default Throwable.TraceInfo implementation for the platform

This functions returns a trace handler, allowing to inspect the current stack trace.

IMPORTANT NOTE! the returned trace is potentially not GC allocated, and so you must call defaultTraceDeallocator when you are finished with the TraceInfo

Throwable.TraceInfo
defaultTraceHandler
(
void* ptr = null
)

Parameters

ptr void*

(Windows only) The context to get the stack trace from. When null (the default), start from the current frame.

Return Value

A Throwable.TraceInfo implementation suitable to iterate over the stack, or null. If called from a finalizer (destructor), always returns null as trace handlers allocate.

Examples

Example of a simple program printing its stack trace

import core.runtime;
import core.stdc.stdio;

void main()
{
    auto trace = defaultTraceHandler(null);
    foreach (line; trace)
    {
        printf("%.*s\n", cast(int)line.length, line.ptr);
    }
    defaultTraceDeallocator(trace);
}

Meta