Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

Catch the runtime exceptions

SPARK objects such as the SPARK::TProblem class and the various API functions rely on the C++ exception mechanism to deal with errors occuring at runtime. Therefore, it is recommended that you execute any SPARK instructions within a try { ... } statement and that you provide the required catch () { ... } statements to process the exceptions.

There are essentially two types of exceptions that will be thrown by the SPARK solver:

Note:
All SPARK specific exceptions are children classes of the class SPARK::XAssertion, whereas the exceptions derived from the class std::exception usually come from the C++ standard library and the Standard Template Library (STL).
The next code snippet shows the typical framework used to catch all exceptions arising during the course of the simulation.

    SPARK::TProblem* P = 0;
   
    try {
     ...
    }
   
    catch (const SPARK::XAssertion& x1) { // SPARK specific exceptions
        SPARK::ExitWithError(
                x1.code(),
                __FILE__,
                x1.message(),
                P // Specifiy active problem to ensure proper diagnostic
        );
    }
    catch (const std::exception& x2) { // std exceptions
        SPARK::ExitWithError(
                SPARK::ExitCode_ERROR_RUNTIME_ERROR,
                __FILE__,
                x2.what(),
                P // Specifiy active problem to ensure proper diagnostic
        );
    }
   
    return SPARK::ExitCode_OK;

Note that the catch statements in the default driver exit the simulator by invoking the API function SPARK::ExitWithError().


Generated on 5 Nov 2003 for VisualSPARK 2.01