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))

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.