# How to test if something is a stack trace

**URL:** <https://discourse.julialang.org/t/how-to-test-if-something-is-a-stack-trace/43363>\
**Category:** General Usage\
**Created:** [July 20, 2020, 8:39am UTC](https://discourse.julialang.org/t/how-to-test-if-something-is-a-stack-trace/43363 "2020-07-20T08:39:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tisztamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tisztamo/32/16200_2.png) [@tisztamo](https://discourse.julialang.org/u/tisztamo)\
**Post date:** [July 20, 2020, 8:39am UTC](https://discourse.julialang.org/t/how-to-test-if-something-is-a-stack-trace/43363/1 "2020-07-20T08:39:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [July 20, 2020, 9:46am UTC](https://discourse.julialang.org/t/how-to-test-if-something-is-a-stack-trace/43363/2 "2020-07-20T09:46:44Z")

</div>

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

```julia
is_stacktrace(x) = x isa AbstractVector{StackTraces.StackFrame}

```

---

<div class="post-metadata">

**Author:** ![tisztamo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tisztamo/32/16200_2.png) [@tisztamo](https://discourse.julialang.org/u/tisztamo)\
**Post date:** [July 20, 2020, 10:08am UTC](https://discourse.julialang.org/t/how-to-test-if-something-is-a-stack-trace/43363/3 "2020-07-20T10:08:01Z")

</div>

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.
