Initializing help system before first use

Exceptions

The Xpress Python interface raises its own exceptions in the event of a modeling, interface, or solver issue. There are three types of exceptions:

  • xpress.ModelError: it is raised in case of an issue in modelling a problem, for instance if an incorrect constraint sign is given or if a problem is amended an object that is neither a variable, a constraint, or a SOS;
  • xpress.InterfaceError: raised when the issue can be ascribed to the API and the way it is used, for instance when not passing mandatory arguments or specifying incorrect ones in an API function;
  • xpress.SolverError: raised when the Xpress Optimizer or Xpress-SLP returns an error that is given by the solver even though the model was specified correctly and the interface functions were used correctly.

As always with Python, one can use the try/except construct in order to analyze the raised exception as in the following example

import xpress as xp
p = xp.problem()
x = getVariable() # assume getVariable is defined elsewhere
try:
  p.addVariable(x)
except xp.ModelError as e:
  print ("Modeling error:", repr(e))