# How to get last error message from REPL?

**URL:** <https://discourse.julialang.org/t/how-to-get-last-error-message-from-repl/102695>\
**Category:** New to Julia\
**Tags:** error-message\
**Created:** [August 10, 2023, 8:59pm UTC](https://discourse.julialang.org/t/how-to-get-last-error-message-from-repl/102695 "2023-08-10T20:59:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinfreedom](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jinfreedom](https://discourse.julialang.org/u/jinfreedom)\
**Post date:** [August 10, 2023, 8:59pm UTC](https://discourse.julialang.org/t/how-to-get-last-error-message-from-repl/102695/1 "2023-08-10T20:59:51Z")

</div>

Is there a quick way to re-display the last error message from REPL, without the stacktrace?

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [August 10, 2023, 9:58pm UTC](https://discourse.julialang.org/t/how-to-get-last-error-message-from-repl/102695/2 "2023-08-10T21:58:32Z")

</div>

```julia
julia> sqrt(-1)
ERROR: DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(f::Symbol, x::Float64)
   @ Base.Math ./math.jl:33
 [2] sqrt
   @ ./math.jl:677 [inlined]
 [3] sqrt(x::Int64)
   @ Base.Math ./math.jl:1491
 [4] top-level scope
   @ REPL[5]:1

julia> err.stack[1].exception
DomainError(-1.0, "sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).")

```

---

<div class="post-metadata">

**Author:** ![jinfreedom](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jinfreedom](https://discourse.julialang.org/u/jinfreedom)\
**Post date:** [August 10, 2023, 10:07pm UTC](https://discourse.julialang.org/t/how-to-get-last-error-message-from-repl/102695/3 "2023-08-10T22:07:48Z")

</div>

> [@tim.holy](#):
>
> `julia> err.stack[1].exception`

so `err` here is a system generated variable? I often times use it in my code for numerical error value. It looks like my `err` will be overwritten in REPL if an error occurred: I guess this is something to live with? Not a big deal though. Thanks.

```julia
julia> err=1e-3
0.001

julia> sqrt(-1)
ERROR: DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(f::Symbol, x::Float64)
   @ Base.Math ./math.jl:33
 [2] sqrt
   @ ./math.jl:677 [inlined]
 [3] sqrt(x::Int64)
   @ Base.Math ./math.jl:1491
 [4] top-level scope
   @ REPL[19]:1

julia> err
1-element ExceptionStack:
DomainError with -1.0:

```

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [August 11, 2023, 10:37am UTC](https://discourse.julialang.org/t/how-to-get-last-error-message-from-repl/102695/4 "2023-08-11T10:37:56Z")

</div>

If your own `err`s are in functions or any other delimited scope, there is no conflict between them.
