ILOG CPLEX 11.0 Getting Started > Tutorials > Concert Technology Tutorial for C++ Users > The Anatomy of an ILOG Concert Technology C++ Application > Handling Errors |
Handling Errors |
INDEX PREVIOUS NEXT |
Concert Technology provides two lines of defense for dealing with error conditions, suited for addressing two kinds of errors. The first kind covers simple programming errors. Examples of this kind are: trying to use empty handle objects or passing arrays of incompatible lengths to functions.
This kind of error is usually an oversight and should not occur in a correct program. In order not to pay any runtime cost for correct programs asserting such conditions, the conditions are checked using assert
statements. The checking is disabled for production runs if compiled with the -DNDEBUG
compiler option.
The second kind of error is more complex and cannot generally be avoided by correct programming. An example is memory exhaustion. The data may simply require too much memory, even when the program is correct. This kind of error is always checked at runtime. In cases where such an error occurs, Concert Technology throws a C++ exception.
In fact, Concert Technology provides a hierarchy of exception classes that all derive from the common base class IloException
. Exceptions derived from this class are the only kind of exceptions that are thrown by Concert Technology. The exceptions thrown by IloCplex
objects all derive from class IloAlgorithm::Exception
or IloCplex::Exception
.
To handle exceptions gracefully in a Concert Technology application, include all of the code in a try/catch
clause, like this:
If code other than Concert Technology code is used in the part of that sample denoted by ...
, all other exceptions will be caught with the statement catch(...)
. Doing so is good practice, as it makes sure that no exception is unhandled.
Copyright © 1987-2007 ILOG S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |