cantera/doc/doxygen/except.cpp
Ray Speth 54efbaa320 Rewrote exception handling to be more general and more explicit
CanteraError inerits from std:exception, so now it has a what() method
that is used to print a message describing the exception. Adding an
exception to the Cantera error stack now requires explicitly calling
the .save() method.
2012-03-05 20:45:56 +00:00

24 lines
499 B
C++

#include "cantera/thermo.h"
//
// artifical example of throwing and catching a CanteraError exception.
//
using namespace Cantera;
void mycode()
{
ThermoPhase* gas = newPhase("h2o2.cti","ohmech");
if (gas->temperature() < 3000.0) {
throw CanteraError("mycode","test of exception throwing and catching");
}
}
int main()
{
try {
mycode();
} catch (CanteraError& err) {
std::cout << err.what() << std::endl;
error("program terminating.");
}
}