7.2 Errors and exceptionsΒΆ

Response codes

Almost every function in Optimizer API for C returns a response code, which is an integer (implemented as the enum MSKrescodee), informing if the requested operation was performed correctly, and if not, what error occurred. The expected response, indicating successful execution, is always MSK_RES_OK. It is a good idea to check the response code every time to avoid silent fails such as for instance:

  • referencing a nonexisting variable (for example with too large index),
  • defining an invalid value for a parameter,
  • accessing an undefined solution,
  • repeating a variable name, etc.

The one case where it is extremely important to check the response code is during optimization, when MSK_optimize is invoked. We will say more about this in Sec. 7.1 (Accessing the solution).

A numerical response code can be converted into a human-readable description using MSK_getcodedesc. A full list of response codes, error, warning and termination codes can be found in the API reference. For example, the following code

  res = MSK_putdouparam(task, MSK_DPAR_INTPNT_CO_TOL_REL_GAP, -1.0e-7);
  if (res != MSK_RES_OK) {
    MSK_getcodedesc(res, symb, str);
    printf("Error %s(%d): %s\n", symb, res, str); 

will produce as output:

Error MSK_RES_ERR_PARAM_IS_TOO_SMALL(1216): A parameter value is too small.

Optimizer errors and warnings

The optimizer may also produce warning messages. They indicate non-critical but important events, that will not prevent solver execution, but may be an indication that something in the optimization problem might be improved. Warning messages are normally printed to a log stream (see Sec. 7.3 (Input/Output)). A typical warning is, for example:

MOSEK warning 53: A numerically large upper bound value  6.6e+09 is specified for constraint 'C69200' (46020).

Warnings can also be suppressed by setting the MSK_IPAR_MAX_NUM_WARNINGS parameter to zero, if they are well-understood.

The user can also register a dedicated callback function to handle all errors and warnings. This is done with MSK_putresponsefunc.