These classes and related functions are used to handle errors and unknown events within Cantera. More...
Classes | |
class | CanteraError |
Base class for exceptions thrown by Cantera classes. More... | |
class | ArraySizeError |
Array size error. More... | |
class | ElementRangeError |
An element index is out of range. More... | |
class | SpeciesRangeError |
Specific fatal error indicating that the index of a species is out of range. More... | |
Defines | |
#define | AssertTrace(expr) ((expr) ? (void) 0 : throw Cantera::CanteraError(STR_TRACE, std::string("failed assert: ") + #expr)) |
Assertion must be true or an error is thrown. | |
#define | AssertThrow(expr, procedure) ((expr) ? (void) 0 : throw Cantera::CanteraError(procedure, std::string("failed assert: ") + #expr)) |
Assertion must be true or an error is thrown. | |
#define | AssertThrowMsg(expr, procedure, message) ((expr) ? (void) 0 : throw Cantera::CanteraError(procedure + std::string(": at failed assert: \"") + std::string(#expr) + std::string("\""), message)) |
Assertion must be true or an error is thrown. | |
Functions | |
void | deprecatedMethod (std::string classnm, std::string oldnm, std::string newnm) |
Print a warning when a deprecated method is called. | |
void | removeAtVersion (std::string func, std::string version) |
Throw an error condition for a procedure that has been removed. | |
int | nErrors () |
Return the number of errors that have been encountered so far. | |
std::string | lastErrorMessage () |
Returns the last error message. | |
void | setError (std::string r, std::string msg) |
Set an error condition in the application class without throwing an exception. | |
void | showErrors (std::ostream &f) |
Prints all of the error messages to an ostream. | |
void | showErrors () |
Print all of the error messages using function writelog of class logger. | |
void | popError () |
Discard the last error message. | |
void | addError (std::string r, std::string msg) |
Set an error condition in the application class without throwing an exception. | |
int | getErrorCount () |
Return the number of errors that have been encountered so far. | |
void | popError () |
Discard the last error message. | |
std::string | lastErrorMessage () |
Retrieve the last error message in a string. | |
void | getErrors (std::ostream &f) |
Prints all of the error messages to an ostream. | |
void | logErrors () |
Prints all of the error messages using writelog. | |
void | addError (std::string r, std::string msg) |
Set an error condition in the application class without throwing an exception. | |
void | popError () |
Discard the last error message. | |
std::string | lastErrorMessage () |
Retrieve the last error message in a string. | |
void | getErrors (std::ostream &f) |
Prints all of the error messages to an ostream. | |
void | logErrors () |
Prints all of the error messages using writelog. |
These classes and related functions are used to handle errors and unknown events within Cantera.
The general idea is that exceptions are thrown using the common base class called CanteraError. Derived types of CanteraError characterize what type of error is thrown. A list of all of the thrown errors is kept in the Application class.
Any exceptions which are not caught cause a fatal error exit from the program.
Below is an example of how to catch errors that throw the CanteraError class. In general, all Cantera C++ programs will have this basic structure.
#include <cantera/Cantera.h> void demoprog() { // Calls Cantera } int main() { try { demoprog(); } catch (CanteraError) { showErrors(cout); } }
The function showErrors() will print out the fatal error condition to standard output.
A group of defines may be used during debugging to assert conditions which should be true. These are named AssertTrace(), AssertThrow(), and AssertThrowMsg(). Examples of their usage is given below.
AssertTrace(p == OneAtm); AssertThrow(p == OneAtm, "Kinetics::update"); AssertThrowMsg(p == OneAtm, "Kinetics::update", "Algorithm limited to atmospheric pressure");
Their first argument is a boolean. If the boolean is not true, a CanteraError is thrown, with descriptive information indicating where the error occured. These functions may be eliminated from the source code, if the -DNDEBUG option is specified to the compiler.
#define AssertThrow | ( | expr, | |||
procedure | ) | ((expr) ? (void) 0 : throw Cantera::CanteraError(procedure, std::string("failed assert: ") + #expr)) |
Assertion must be true or an error is thrown.
Assertion must be true or else a CanteraError is thrown. A diagnostic string indicating where the error occured is added to the thrown object.
expr | Boolean expression that must be true | |
procedure | Character string or std:string expression indicating the procedure where the assertion failed |
Definition at line 218 of file ctexceptions.h.
Referenced by MolalityVPSSTP::getActivityCoefficients(), IdealMolalSoln::getChemPotentials(), PDSS::initThermo(), PDSS::initThermoXML(), and GeneralSpeciesThermo::install_STIT().
#define AssertThrowMsg | ( | expr, | |||
procedure, | |||||
message | ) | ((expr) ? (void) 0 : throw Cantera::CanteraError(procedure + std::string(": at failed assert: \"") + std::string(#expr) + std::string("\""), message)) |
Assertion must be true or an error is thrown.
Assertion must be true or else a CanteraError is thrown. A diagnostic string indicating where the error occured is added to the thrown object.
expr | Boolean expression that must be true | |
procedure | Character string or std:string expression indicating the procedure where the assertion failed | |
message | Character string or std:string expression contaiing a descriptive message is added to the thrown error condition. |
Definition at line 236 of file ctexceptions.h.
Referenced by VPStandardStateTP::_updateStandardStateThermo(), Messages::endLogGroup(), Elements::entropyElement298(), and MolalityVPSSTP::setSolvent().
#define AssertTrace | ( | expr | ) | ((expr) ? (void) 0 : throw Cantera::CanteraError(STR_TRACE, std::string("failed assert: ") + #expr)) |
Assertion must be true or an error is thrown.
Assertion must be true or else a CanteraError is thrown. A diagnostic string containing the file and line number, indicating where the error occured is added to the thrown object.
expr | Boolean expression that must be true |
Definition at line 205 of file ctexceptions.h.
Referenced by HMWSoln::applyphScale(), Elements::entropyElement298(), VPStandardStateTP::initThermoXML(), HMWSoln::s_updateScaling_pHScaling(), HMWSoln::s_updateScaling_pHScaling_dT(), and HMWSoln::s_updateScaling_pHScaling_dT2().
void addError | ( | std::string | r, | |
std::string | msg | |||
) | [inline, inherited] |
Set an error condition in the application class without throwing an exception.
This routine adds an error message to the end of the stack of errors that Cantera accumulates in the Application class.
r | location | |
msg | Description of the error |
Definition at line 590 of file misc.cpp.
References Application::pMessenger.
Referenced by CanteraError::CanteraError(), and Cantera::setError().
void addError | ( | std::string | r, | |
std::string | msg | |||
) | [inherited] |
Set an error condition in the application class without throwing an exception.
This routine adds an error message to the end of the stack of errors that Cantera accumulates in the Application class.
r | location | |
msg | Description of the error |
Definition at line 1247 of file misc.cpp.
References Messages::errorMessage, and Messages::errorRoutine.
void deprecatedMethod | ( | std::string | classnm, | |
std::string | oldnm, | |||
std::string | newnm | |||
) |
Print a warning when a deprecated method is called.
These methods are slated to go away in future releases of Cantera. The developer should work towards eliminating the use of these methods in the near future.
classnm | Class the method belongs to | |
oldnm | Name of the deprecated method | |
newnm | Name of the method users should use instead |
Definition at line 1482 of file misc.cpp.
References Cantera::writelog().
Referenced by Kinetics::phase(), Kinetics::start(), and ThermoPhase::updateDensity().
int getErrorCount | ( | ) | [inherited] |
Return the number of errors that have been encountered so far.
Definition at line 1122 of file misc.cpp.
References Messages::errorMessage.
void getErrors | ( | std::ostream & | f | ) | [inline, inherited] |
Prints all of the error messages to an ostream.
Print all of the error messages using function writelog. Write out all of the saved error messages to the ostream f Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages to the ostream and then clears them from internal storage.
f | ostream which will receive the error messages |
Definition at line 630 of file misc.cpp.
References Application::pMessenger.
Referenced by Cantera::showErrors().
void getErrors | ( | std::ostream & | f | ) | [inherited] |
Prints all of the error messages to an ostream.
Print all of the error messages using function writelog. Write out all of the saved error messages to the ostream f Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages to the ostream and then clears them from internal storage.
f | ostream which will receive the error messages |
Definition at line 1183 of file misc.cpp.
References Messages::errorMessage, and Messages::errorRoutine.
std::string lastErrorMessage | ( | ) | [inline, inherited] |
Retrieve the last error message in a string.
This routine will retrieve the last error message and return it in the return string.
Definition at line 615 of file misc.cpp.
References Application::pMessenger.
Referenced by Cantera::lastErrorMessage().
std::string lastErrorMessage | ( | ) | [inherited] |
Retrieve the last error message in a string.
This routine will retrieve the last error message and return it in the return string.
Definition at line 1156 of file misc.cpp.
References Messages::errorMessage, and Messages::errorRoutine.
string lastErrorMessage | ( | ) |
Returns the last error message.
Definition at line 1151 of file misc.cpp.
References Cantera::app(), and Application::lastErrorMessage().
void logErrors | ( | ) | [inline, inherited] |
Prints all of the error messages using writelog.
Print all of the error messages using function writelog. Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages and then clears them from internal storage.
Definition at line 642 of file misc.cpp.
References Application::pMessenger.
Referenced by Cantera::showErrors().
void logErrors | ( | ) | [inherited] |
Prints all of the error messages using writelog.
Print all of the error messages using function writelog. Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages and then clears them from internal storage.
Definition at line 1216 of file misc.cpp.
References Messages::errorMessage, Messages::errorRoutine, and Messages::writelog().
int nErrors | ( | ) |
Return the number of errors that have been encountered so far.
Definition at line 1117 of file misc.cpp.
References Cantera::app(), and Application::getErrorCount().
void popError | ( | ) | [inline, inherited] |
Discard the last error message.
Cantera saves a stack of exceptions that it has caught in the Application class. This routine eliminates the last exception to be added to that stack.
Definition at line 606 of file misc.cpp.
References Application::pMessenger.
Referenced by Cantera::popError().
void popError | ( | ) | [inherited] |
Discard the last error message.
Cantera saves a stack of exceptions that it has caught in the Application class. This routine eliminates the last exception to be added to that stack.
Definition at line 1138 of file misc.cpp.
References Messages::errorMessage, and Messages::errorRoutine.
void popError | ( | ) |
Discard the last error message.
Cantera saves a stack of exceptions that it has caught in the Application class. This routine eliminates the last exception to be added to that stack.
Definition at line 1133 of file misc.cpp.
References Cantera::app(), and Application::popError().
Referenced by SpeciesThermoFactory::newSpeciesThermo(), SpeciesThermoFactory::newSpeciesThermoOpt(), and VPSSMgrFactory::newVPSSMgr().
void removeAtVersion | ( | std::string | func, | |
std::string | version | |||
) |
Throw an error condition for a procedure that has been removed.
func | String name for the function within which the error was generated. | |
version | Version of Cantera that first removed this function. |
Definition at line 1491 of file misc.cpp.
References Cantera::writelog().
void setError | ( | std::string | r, | |
std::string | msg | |||
) |
Set an error condition in the application class without throwing an exception.
This routine adds an error message to the end of the stack of errors that Cantera accumulates in the Application class.
r | Procedure name which is generating the error condition | |
msg | Descriptive message of the error condition. |
Definition at line 1242 of file misc.cpp.
References Application::addError(), and Cantera::app().
Referenced by XML_IllegalUnits::XML_IllegalUnits(), XML_NoChild::XML_NoChild(), and XML_TagMismatch::XML_TagMismatch().
void showErrors | ( | ) |
Print all of the error messages using function writelog of class logger.
Print all of the error messages using the member function writelog of class logger. Write out all of the saved error messages to the log device. Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages to the log, usually stdout, and then clears them from internal storage.
Definition at line 1211 of file misc.cpp.
References Cantera::app(), and Application::logErrors().
void showErrors | ( | std::ostream & | f | ) |
Prints all of the error messages to an ostream.
Write out all of the saved error messages to the ostream f using the member function writelog of class logger. Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages to the ostream and then clears them from internal storage.
f | ostream which will receive the error messages |
Definition at line 1178 of file misc.cpp.
References Cantera::app(), and Application::getErrors().