# How to get stacktrace and line numbers after jl\_exception\_occurred?

**URL:** <https://discourse.julialang.org/t/how-to-get-stacktrace-and-line-numbers-after-jl-exception-occurred/73031>\
**Category:** General Usage\
**Tags:** embedding\
**Created:** [December 13, 2021, 4:57pm UTC](https://discourse.julialang.org/t/how-to-get-stacktrace-and-line-numbers-after-jl-exception-occurred/73031 "2021-12-13T16:57:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobertN](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@RobertN](https://discourse.julialang.org/u/RobertN)\
**Post date:** [December 13, 2021, 4:57pm UTC](https://discourse.julialang.org/t/how-to-get-stacktrace-and-line-numbers-after-jl-exception-occurred/73031/1 "2021-12-13T16:57:57Z")

</div>

I’m loading a string from a file and passing it to `jl_eval_string`. When there is an error in the file I can tell because `jl_exception_occured()` returns non-null. But how do I get a stack trace with line numbers from that exception object, for use in the C/C++ code?

```c++
auto result = jl_eval_string(code);
auto ex = jl_exception_occurred();
    
std::cout << "result: " << result << std::endl;
std::cout << "ex: " << ex << std::endl;
if (ex) {
        jl_static_show(jl_stderr_stream(), ex); 
}

```

That `jl_static_show` call prints:

> ErrorException(“syntax: “w:Int64” is not a valid function argument name”)

That helps, but I’d like to get this info below, which I see if I include the file in the REPL:

```plaintext
julia> include("/Users/rob/Library/.../main.jl")
ERROR: LoadError: syntax: "w:Int64" is not a valid function argument name around /Users/rob/Library/Containers/.../main.jl:15
Stacktrace:
 [1] top-level scope
   @ ~/Library/Containers/.../main.jl:15
 [2] include(fname::String)
   @ Base.MainInclude ./client.jl:451
 [3] top-level scope
   @ REPL[10]:1
in expression starting at /Users/rob/Library/.../main.jl:15

```
