# How to access CPLEX.CplexError in JuMP 0.18?

**URL:** <https://discourse.julialang.org/t/how-to-access-cplex-cplexerror-in-jump-0-18/22598>\
**Category:** Optimization (Mathematical)\
**Created:** [April 1, 2019, 1:43pm UTC](https://discourse.julialang.org/t/how-to-access-cplex-cplexerror-in-jump-0-18/22598 "2019-04-01T13:43:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [April 1, 2019, 1:43pm UTC](https://discourse.julialang.org/t/how-to-access-cplex-cplexerror-in-jump-0-18/22598/1 "2019-04-01T13:43:45Z")

</div>

Dear community,  
I always start cplex like for instance:

```julia
try
    status = solve(model)
    println("status: ", status)
    println("obj_val: ", getobjectivevalue(model))
catch msg
    println("ERROR SOLVING MODEL: ", msg)
end

```

In my case typeof(msg) returns CPLEX.CplexError if solve(model) is catched, and from the example above I obtain

```julia
ERROR SOLVING MODEL: CPLEX.CplexError(1001, "CPLEX Error 1001: Out of memory.\n")

```

How can I obtain which error cplex throwed? Basically I am searching for somthing like

```julia
if CPLEX.CplexError(??) == 1001
   #do something
end

```

I also tried in the example above to convert the message to a string, i.e., string(msg), but this did work out either (and it does not seem to be a good solution to me).

Thank you in advance, mike

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 1, 2019, 1:46pm UTC](https://discourse.julialang.org/t/how-to-access-cplex-cplexerror-in-jump-0-18/22598/2 "2019-04-01T13:46:58Z")

</div>

Here is the definition of `CplexError`.

> <https://github.com/jump-dev/CPLEX.jl/blob/bb3f45c236fb0afb2fa2ed75c448e17b9a64a61e/src/cpx_env.jl#L85-L92>

I guess you want

```julia
if msg.code == 1001
    # do something
end

```

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [April 1, 2019, 1:57pm UTC](https://discourse.julialang.org/t/how-to-access-cplex-cplexerror-in-jump-0-18/22598/3 "2019-04-01T13:57:50Z")

</div>

Thank you so much - this is exactly what I needed 🙂

---

<div class="post-metadata">

**Author:** ![Paul\_McVay](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_mcvay/32/4307_2.png) [@Paul\_McVay](https://discourse.julialang.org/u/Paul_McVay)\
**Post date:** [March 2, 2021, 7:23pm UTC](https://discourse.julialang.org/t/how-to-access-cplex-cplexerror-in-jump-0-18/22598/4 "2021-03-02T19:23:35Z")

</div>

There no longer seems to be a `code` field when you catch an error. Is this accurate? Is there a workaround?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 2, 2021, 8:12pm UTC](https://discourse.julialang.org/t/how-to-access-cplex-cplexerror-in-jump-0-18/22598/5 "2021-03-02T20:12:08Z")

</div>

CPLEX.jl has been completely re-written, so this post is no longer relevant. Please start a new post if you have questions.

---

<div class="post-metadata">

**Author:** ![Paul\_McVay](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_mcvay/32/4307_2.png) [@Paul\_McVay](https://discourse.julialang.org/u/Paul_McVay)\
**Post date:** [March 2, 2021, 8:18pm UTC](https://discourse.julialang.org/t/how-to-access-cplex-cplexerror-in-jump-0-18/22598/6 "2021-03-02T20:18:27Z")

</div>

Sure. If someone finds this post, here is the new thread [Error Handling JuMP and CPLEX](https://discourse.julialang.org/t/error-handling-jump-and-cplex/56360)
