How to test if something is a stack trace

I have a function that works on an array and collects the exceptions and backtraces encountered during processing.

For the tests I need to check if something is a backtrace. The following works, but seems very fragile:

typeof(backtrace()) === Array{Union{Ptr{Nothing}, Base.InterpreterIP},1}

Is there a better way to check this?

Perhaps collect stacktraces rather than backtraces? The docs for stacktrace say it returns a vector of StackFrames, so this should be less fragile:

is_stacktrace(x) = x isa AbstractVector{StackTraces.StackFrame}
2 Likes

Thanks, I did not know that backtraces and stacktraces are different things, and I used catch_backtrace(), but stacktrace() can also convert, so it is fine now.

1 Like