8.2 Errors and exceptions¶
Almost every method in Fusion API for Matlab can throw an exception informing that the requested operation was not performed correctly, and indicating the type of error that occurred. This is the case in situations such as for instance:
- incompatible dimensions in a linear expression,
- defining an invalid value for a parameter,
- accessing an undefined solution,
- repeating a variable name, etc.
It is therefore a good idea to catch exceptions of type
FusionException and its specific subclasses. The one case where it is extremely important to do so is when
Model.solve is invoked. We will say more about this in Sec. 8.1 (Accessing the solution).
The exception contains a short diagnostic message. They can be accessed as in the following example.
try M.setSolverParam('intpntCoTolRelGap', 1.01); catch disp('Wrong parameter value');
It will produce as output:
Error: Invalid value for parameter (intpntCoTolRelGap)
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. 8.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).