How to access CPLEX.CplexError in JuMP 0.18?

Dear community,
I always start cplex like for instance:

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

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

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

Here is the definition of CplexError.

I guess you want

if msg.code == 1001
    # do something
end
2 Likes

Thank you so much - this is exactly what I needed :slight_smile:

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

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

Sure. If someone finds this post, here is the new thread Error Handling JuMP and CPLEX