Replace overly-specific exception types with CanteraError

Deprecate exception types which are now unused.
This commit is contained in:
Ray Speth 2016-02-04 19:34:26 -05:00
parent f44b5fed57
commit b55c8fe813
11 changed files with 106 additions and 78 deletions

View file

@ -18,11 +18,14 @@ class FuncData;
/**
* Exception thrown when a CVODES error is encountered.
* @deprecated Unused. To be removed after Cantera 2.3.
*/
class CVodesErr : public CanteraError
{
public:
explicit CVodesErr(const std::string& msg) : CanteraError("CVodesIntegrator", msg) {}
explicit CVodesErr(const std::string& msg) : CanteraError("CVodesIntegrator", msg) {
warn_deprecated("class CVodesErr", "To be removed after Cantera 2.3.");
}
};
/**

View file

@ -38,9 +38,12 @@ public:
/*!
* @param routine Name of calling routine
* @param msg Informative message
* @deprecated Unused. To be removed after Cantera 2.3.
*/
CELapackError(const std::string& routine, const std::string& msg) :
CanteraError(routine + " LAPACK ERROR", msg) {
warn_deprecated("class CELapackError",
"To be removed after Cantera 2.3.");
}
};
@ -52,9 +55,8 @@ public:
*
* Error handling from BLAS and LAPACK are handled via the following
* formulation. Depending on a variable, a singular matrix or other terminal
* error condition from LAPACK is handled by either throwing an exception of
* type, CELapackError, or by returning the error code condition to the calling
* routine.
* error condition from LAPACK is handled by either throwing an exception or
* by returning the error code condition to the calling routine.
*
* The int variable, m_useReturnErrorCode, determines which method is used. The
* default value of zero means that an exception is thrown. A value of 1 means

View file

@ -25,11 +25,14 @@ namespace Cantera
/**
* Exception thrown when a IDA error is encountered.
* @deprecated Unused. To be removed after Cantera 2.3.
*/
class IDA_Err : public CanteraError
{
public:
explicit IDA_Err(const std::string& msg) : CanteraError("IDA_Solver", msg) {}
explicit IDA_Err(const std::string& msg) : CanteraError("IDA_Solver", msg) {
warn_deprecated("class IDA_Err", "To be removed after Cantera 2.3.");
}
};

View file

@ -8,13 +8,6 @@
namespace tpx
{
class TPX_Error : public Cantera::CanteraError
{
public:
TPX_Error(const std::string& p, const std::string& e) :
CanteraError(p, e) { }
};
namespace PropertyPair
{
enum type {

View file

@ -182,7 +182,7 @@ void CVodesIntegrator::setMethod(MethodType t)
} else if (t == Adams_Method) {
m_method = CV_ADAMS;
} else {
throw CVodesErr("unknown method");
throw CanteraError("CVodesIntegrator::setMethod", "unknown method");
}
}
@ -225,7 +225,7 @@ void CVodesIntegrator::setIterator(IterType t)
} else if (t == Functional_Iter) {
m_iter = CV_FUNCTIONAL;
} else {
throw CVodesErr("unknown iterator");
throw CanteraError("CVodesIntegrator::setIterator", "unknown iterator");
}
}
@ -250,7 +250,7 @@ void CVodesIntegrator::sensInit(double t0, FuncEval& func)
CV_STAGGERED, CVSensRhsFn(0), m_yS);
if (flag != CV_SUCCESS) {
throw CVodesErr("Error in CVodeSensMalloc");
throw CanteraError("CVodesIntegrator::sensInit", "Error in CVodeSensMalloc");
}
vector_fp atol(m_np, m_abstolsens);
double rtol = m_reltolsens;
@ -273,7 +273,8 @@ void CVodesIntegrator::initialize(double t0, FuncEval& func)
}
// check abs tolerance array size
if (m_itol == CV_SV && m_nabs < m_neq) {
throw CVodesErr("not enough absolute tolerance values specified.");
throw CanteraError("CVodesIntegrator::initialize",
"not enough absolute tolerance values specified.");
}
func.getState(NV_DATA_S(m_y));
@ -287,17 +288,21 @@ void CVodesIntegrator::initialize(double t0, FuncEval& func)
//! CV_NEWTON - use Newton's method
m_cvode_mem = CVodeCreate(m_method, m_iter);
if (!m_cvode_mem) {
throw CVodesErr("CVodeCreate failed.");
throw CanteraError("CVodesIntegrator::initialize",
"CVodeCreate failed.");
}
int flag = CVodeInit(m_cvode_mem, cvodes_rhs, m_t0, m_y);
if (flag != CV_SUCCESS) {
if (flag == CV_MEM_FAIL) {
throw CVodesErr("Memory allocation failed.");
throw CanteraError("CVodesIntegrator::initialize",
"Memory allocation failed.");
} else if (flag == CV_ILL_INPUT) {
throw CVodesErr("Illegal value for CVodeInit input argument.");
throw CanteraError("CVodesIntegrator::initialize",
"Illegal value for CVodeInit input argument.");
} else {
throw CVodesErr("CVodeInit failed.");
throw CanteraError("CVodesIntegrator::initialize",
"CVodeInit failed.");
}
}
CVodeSetErrHandlerFn(m_cvode_mem, &cvodes_err, this);
@ -309,11 +314,14 @@ void CVodesIntegrator::initialize(double t0, FuncEval& func)
}
if (flag != CV_SUCCESS) {
if (flag == CV_MEM_FAIL) {
throw CVodesErr("Memory allocation failed.");
throw CanteraError("CVodesIntegrator::initialize",
"Memory allocation failed.");
} else if (flag == CV_ILL_INPUT) {
throw CVodesErr("Illegal value for CVodeInit input argument.");
throw CanteraError("CVodesIntegrator::initialize",
"Illegal value for CVodeInit input argument.");
} else {
throw CVodesErr("CVodeInit failed.");
throw CanteraError("CVodesIntegrator::initialize",
"CVodeInit failed.");
}
}
@ -322,7 +330,8 @@ void CVodesIntegrator::initialize(double t0, FuncEval& func)
flag = CVodeSetUserData(m_cvode_mem, m_fdata.get());
if (flag != CV_SUCCESS) {
throw CVodesErr("CVodeSetUserData failed.");
throw CanteraError("CVodesIntegrator::initialize",
"CVodeSetUserData failed.");
}
if (func.nparams() > 0) {
sensInit(t0, func);
@ -370,7 +379,8 @@ void CVodesIntegrator::applyOptions()
CVBand(m_cvode_mem, N, nu, nl);
#endif
} else {
throw CVodesErr("unsupported option");
throw CanteraError("CVodesIntegrator::applyOptions",
"unsupported option");
}
if (m_maxord > 0) {

View file

@ -132,7 +132,7 @@ int solve(DenseMatrix& A, double* b, size_t nrhs, size_t ldb)
if (A.m_printLevel) {
writelogf("solve(DenseMatrix& A, double* b): Can only solve a square matrix\n");
}
throw CELapackError("solve(DenseMatrix& A, double* b)", "Can only solve a square matrix");
throw CanteraError("solve(DenseMatrix& A, double* b)", "Can only solve a square matrix");
}
ct_dgetrf(A.nRows(), A.nColumns(), A.ptrColumn(0),
A.nRows(), &A.ipiv()[0], info);

View file

@ -201,7 +201,8 @@ void IDA_Solver::setTolerances(double reltol, double* abstol)
if (m_ida_mem) {
int flag = IDASVtolerances(m_ida_mem, m_reltol, m_abstol);
if (flag != IDA_SUCCESS) {
throw IDA_Err("Memory allocation failed.");
throw CanteraError("IDA_Solver::setTolerances",
"Memory allocation failed.");
}
}
}
@ -214,7 +215,8 @@ void IDA_Solver::setTolerances(doublereal reltol, doublereal abstol)
if (m_ida_mem) {
int flag = IDASStolerances(m_ida_mem, m_reltol, m_abstols);
if (flag != IDA_SUCCESS) {
throw IDA_Err("Memory allocation failed.");
throw CanteraError("IDA_Solver::setTolerances",
"Memory allocation failed.");
}
}
}
@ -269,7 +271,8 @@ void IDA_Solver::setJacobianType(int formJac)
if (m_ida_mem && m_formJac == 1) {
int flag = IDADlsSetDenseJacFn(m_ida_mem, ida_jacobian);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDADlsSetDenseJacFn failed.");
throw CanteraError("IDA_Solver::setJacobianType",
"IDADlsSetDenseJacFn failed.");
}
}
}
@ -342,31 +345,35 @@ void IDA_Solver::init(doublereal t0)
flag = IDAInit(m_ida_mem, ida_resid, m_t0, m_y, m_ydot);
if (flag != IDA_SUCCESS) {
if (flag == IDA_MEM_FAIL) {
throw IDA_Err("Memory allocation failed.");
throw CanteraError("IDA_Solver::init",
"Memory allocation failed.");
} else if (flag == IDA_ILL_INPUT) {
throw IDA_Err("Illegal value for IDAMalloc input argument.");
throw CanteraError("IDA_Solver::init",
"Illegal value for IDAMalloc input argument.");
} else {
throw IDA_Err("IDAMalloc failed.");
throw CanteraError("IDA_Solver::init", "IDAMalloc failed.");
}
}
flag = IDASVtolerances(m_ida_mem, m_reltol, m_abstol);
if (flag != IDA_SUCCESS) {
throw IDA_Err("Memory allocation failed.");
throw CanteraError("IDA_Solver::init", "Memory allocation failed.");
}
} else {
flag = IDAInit(m_ida_mem, ida_resid, m_t0, m_y, m_ydot);
if (flag != IDA_SUCCESS) {
if (flag == IDA_MEM_FAIL) {
throw IDA_Err("Memory allocation failed.");
throw CanteraError("IDA_Solver::init",
"Memory allocation failed.");
} else if (flag == IDA_ILL_INPUT) {
throw IDA_Err("Illegal value for IDAMalloc input argument.");
throw CanteraError("IDA_Solver::init",
"Illegal value for IDAMalloc input argument.");
} else {
throw IDA_Err("IDAMalloc failed.");
throw CanteraError("IDA_Solver::init", "IDAMalloc failed.");
}
}
flag = IDASStolerances(m_ida_mem, m_reltol, m_abstols);
if (flag != IDA_SUCCESS) {
throw IDA_Err("Memory allocation failed.");
throw CanteraError("IDA_Solver::init", "Memory allocation failed.");
}
}
@ -375,7 +382,7 @@ void IDA_Solver::init(doublereal t0)
long int N = m_neq;
flag = IDADense(m_ida_mem, N);
if (flag) {
throw IDA_Err("IDADense failed");
throw CanteraError("IDA_Solver::init", "IDADense failed");
}
} else if (m_type == 2) {
long int N = m_neq;
@ -383,13 +390,15 @@ void IDA_Solver::init(doublereal t0)
long int nl = m_mlower;
IDABand(m_ida_mem, N, nu, nl);
} else {
throw IDA_Err("unsupported linear solver type");
throw CanteraError("IDA_Solver::init",
"unsupported linear solver type");
}
if (m_formJac == 1) {
flag = IDADlsSetDenseJacFn(m_ida_mem, ida_jacobian);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDADlsSetDenseJacFn failed.");
throw CanteraError("IDA_Solver::init",
"IDADlsSetDenseJacFn failed.");
}
}
@ -397,56 +406,59 @@ void IDA_Solver::init(doublereal t0)
m_fdata.reset(new ResidData(&m_resid, this, m_resid.nparams()));
flag = IDASetUserData(m_ida_mem, m_fdata.get());
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetUserData failed.");
throw CanteraError("IDA_Solver::init", "IDASetUserData failed.");
}
// set options
if (m_maxord > 0) {
flag = IDASetMaxOrd(m_ida_mem, m_maxord);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetMaxOrd failed.");
throw CanteraError("IDA_Solver::init", "IDASetMaxOrd failed.");
}
}
if (m_maxsteps > 0) {
flag = IDASetMaxNumSteps(m_ida_mem, m_maxsteps);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetMaxNumSteps failed.");
throw CanteraError("IDA_Solver::init", "IDASetMaxNumSteps failed.");
}
}
if (m_h0 > 0.0) {
flag = IDASetInitStep(m_ida_mem, m_h0);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetInitStep failed.");
throw CanteraError("IDA_Solver::init", "IDASetInitStep failed.");
}
}
if (m_tstop > 0.0) {
flag = IDASetStopTime(m_ida_mem, m_tstop);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetStopTime failed.");
throw CanteraError("IDA_Solver::init", "IDASetStopTime failed.");
}
}
if (m_maxErrTestFails >= 0) {
flag = IDASetMaxErrTestFails(m_ida_mem, m_maxErrTestFails);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetMaxErrTestFails failed.");
throw CanteraError("IDA_Solver::init",
"IDASetMaxErrTestFails failed.");
}
}
if (m_maxNonlinIters > 0) {
flag = IDASetMaxNonlinIters(m_ida_mem, m_maxNonlinIters);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetmaxNonlinIters failed.");
throw CanteraError("IDA_Solver::init",
"IDASetmaxNonlinIters failed.");
}
}
if (m_maxNonlinConvFails >= 0) {
flag = IDASetMaxConvFails(m_ida_mem, m_maxNonlinConvFails);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetMaxConvFails failed.");
throw CanteraError("IDA_Solver::init",
"IDASetMaxConvFails failed.");
}
}
if (m_setSuppressAlg != 0) {
flag = IDASetSuppressAlg(m_ida_mem, m_setSuppressAlg);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetSuppressAlg failed.");
throw CanteraError("IDA_Solver::init", "IDASetSuppressAlg failed.");
}
}
}
@ -521,30 +533,30 @@ int IDA_Solver::solve(double tout)
int flag;
flag = IDASetStopTime(m_ida_mem, tout);
if (flag != IDA_SUCCESS) {
throw IDA_Err(" IDA error encountered.");
throw CanteraError("IDA_Solver::solve", "IDA error encountered.");
}
while (tretn < tout) {
if (tout <= m_tcurrent) {
throw IDA_Err(" tout <= tcurrent");
throw CanteraError("IDA_Solver::solve", "tout <= tcurrent");
}
m_told_old = m_told;
m_told = m_tcurrent;
flag = IDASolve(m_ida_mem, tout, &tretn, m_y, m_ydot, IDA_ONE_STEP);
if (flag < 0) {
throw IDA_Err(" IDA error encountered.");
throw CanteraError("IDA_Solver::solve", "IDA error encountered.");
} else if (flag == IDA_TSTOP_RETURN) {
// we've reached our goal, and have actually integrated past it
} else if (flag == IDA_ROOT_RETURN) {
// not sure what to do with this yet
} else if (flag == IDA_WARNING) {
throw IDA_Err(" IDA Warning encountered.");
throw CanteraError("IDA_Solver::solve", "IDA Warning encountered.");
}
m_tcurrent = tretn;
m_deltat = m_tcurrent - m_told;
};
if (flag != IDA_SUCCESS && flag != IDA_TSTOP_RETURN) {
throw IDA_Err(" IDA error encountered.");
throw CanteraError("IDA_Solver::solve", "IDA error encountered.");
}
return flag;
}
@ -554,19 +566,19 @@ double IDA_Solver::step(double tout)
double t;
int flag;
if (tout <= m_tcurrent) {
throw IDA_Err(" tout <= tcurrent");
throw CanteraError("IDA_Solver::step", "tout <= tcurrent");
}
m_told_old = m_told;
m_told = m_tcurrent;
flag = IDASolve(m_ida_mem, tout, &t, m_y, m_ydot, IDA_ONE_STEP);
if (flag < 0) {
throw IDA_Err(" IDA error encountered.");
throw CanteraError("IDA_Solver::step", "IDA error encountered.");
} else if (flag == IDA_TSTOP_RETURN) {
// we've reached our goal, and have actually integrated past it
} else if (flag == IDA_ROOT_RETURN) {
// not sure what to do with this yet
} else if (flag == IDA_WARNING) {
throw IDA_Err(" IDA Warning encountered.");
throw CanteraError("IDA_Solver::step", "IDA Warning encountered.");
}
m_tcurrent = t;
m_deltat = m_tcurrent - m_told;

View file

@ -219,7 +219,7 @@ doublereal SquareMatrix::rcond(doublereal anorm)
}
doublereal rcond = 0.0;
if (m_factored != 1) {
throw CELapackError("SquareMatrix::rcond()", "matrix isn't factored correctly");
throw CanteraError("SquareMatrix::rcond()", "matrix isn't factored correctly");
}
int rinfo = 0;
@ -251,7 +251,7 @@ doublereal SquareMatrix::rcondQR()
}
doublereal rcond = 0.0;
if (m_factored != 2) {
throw CELapackError("SquareMatrix::rcondQR()", "matrix isn't factored correctly");
throw CanteraError("SquareMatrix::rcondQR()", "matrix isn't factored correctly");
}
int rinfo = 0;

View file

@ -107,8 +107,9 @@ static void getVPSSMgrTypes(std::vector<XML_Node*> & spDataNodeList,
ssModel == "constant") {
has_other++;
} else {
throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
spNode->attrib("name"));
throw CanteraError("getVPSSMgrTypes",
"Specified VPSSMgr model {} does not match any known type.",
spNode->attrib("name"));
}
ifound = true;
}
@ -123,8 +124,9 @@ static void getVPSSMgrTypes(std::vector<XML_Node*> & spDataNodeList,
ssModel == "constant") {
has_other++;
} else {
throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
spNode->attrib("name"));
throw CanteraError("getVPSSMgrTypes",
"Specified VPSSMgr model {} does not match any known type.",
spNode->attrib("name"));
}
ifound = true;
}
@ -139,8 +141,9 @@ static void getVPSSMgrTypes(std::vector<XML_Node*> & spDataNodeList,
ssModel == "constant") {
has_other++;
} else {
throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
spNode->attrib("name"));
throw CanteraError("getVPSSMgrTypes",
"Specified VPSSMgr model {} does not match any known type.",
spNode->attrib("name"));
}
ifound = true;
}
@ -172,8 +175,9 @@ static void getVPSSMgrTypes(std::vector<XML_Node*> & spDataNodeList,
ifound = true;
}
} else {
throw UnknownVPSSMgrModel("getVPSSMgrTypes:",
spNode->attrib("name"));
throw CanteraError("getVPSSMgrTypes",
"Specified VPSSMgr model {} does not match any known type.",
spNode->attrib("name"));
}
}
}
@ -255,7 +259,7 @@ VPSSMgr* VPSSMgrFactory::newVPSSMgr(VPStandardStateTP* vp_ptr,
try {
getVPSSMgrTypes(spDataNodeList, inasaIG, inasaCV, ishomateIG, ishomateCV,
isimpleIG, isimpleCV, iwater, itpx, ihptx, iother);
} catch (UnknownVPSSMgrModel) {
} catch (CanteraError) {
iother = 1;
}

View file

@ -30,6 +30,7 @@ public:
/*!
* @param proc Function name error occurred.
* @param VPSSMgrModel Unrecognized species thermo calculator name
* @deprecated Unused. To be removed after Cantera 2.3.
*/
UnknownVPSSMgrModel(const std::string& proc,
const std::string& VPSSMgrModel) :

View file

@ -77,7 +77,7 @@ double Substance::x()
double Substance::Tsat(double p)
{
if (p <= 0.0 || p > Pcrit()) {
throw TPX_Error("Substance::Tsat", "illegal pressure value");
throw CanteraError("Substance::Tsat", "illegal pressure value");
}
int LoopCount = 0;
double tol = 1.e-6*p;
@ -107,7 +107,7 @@ double Substance::Tsat(double p)
LoopCount++;
if (LoopCount > 100) {
T = Tsave;
throw TPX_Error("Substance::Tsat", "No convergence");
throw CanteraError("Substance::Tsat", "No convergence");
}
}
double tsat = T;
@ -236,7 +236,7 @@ void Substance::Set(PropertyPair::type XY, double x0, double y0)
}
break;
default:
throw TPX_Error("Substance::Set", "Invalid input.");
throw CanteraError("Substance::Set", "Invalid input.");
}
}
@ -339,7 +339,7 @@ void Substance::update_sat()
}
if (i >= 20) {
throw TPX_Error("substance::update_sat","no convergence");
throw CanteraError("substance::update_sat","no convergence");
} else {
Pst = pp;
Tslast = T;
@ -362,7 +362,7 @@ double Substance::vprop(propertyFlag::type ijob)
case propertyFlag::P:
return Pp();
default:
throw TPX_Error("Substance::vprop", "invalid job index");
throw CanteraError("Substance::vprop", "invalid job index");
}
}
@ -384,14 +384,14 @@ int Substance::Lever(int itp, double sat, double val, propertyFlag::type ifunc)
psat = sat;
try {
T = Tsat(psat);
} catch (TPX_Error&) {
} catch (CanteraError&) {
// Failure to converge here is not an error
T = Tsave;
Rho = Rhosave;
return 0;
}
} else {
throw TPX_Error("Substance::Lever","general error");
throw CanteraError("Substance::Lever","general error");
}
Set(PropertyPair::TX, T, 1.0);
double Valg = vprop(ifunc);
@ -507,7 +507,7 @@ void Substance::set_xy(propertyFlag::type ifx, propertyFlag::type ify,
} else if (t_here == Tmax()) {
msg += fmt::format("\nAt temperature limit (Tmax = {})", Tmax());
}
throw TPX_Error("Substance::set_xy", msg);
throw CanteraError("Substance::set_xy", msg);
}
}
}
@ -600,7 +600,7 @@ void Substance::set_TPp(double Temp, double Pressure)
Pmax = P_here;
}
if (Vmin >= Vmax) {
throw TPX_Error("Substance::set_TPp","Vmin >= Vmax");
throw CanteraError("Substance::set_TPp","Vmin >= Vmax");
} else if ((Vmin > 0.0) && (Vmax < Big)) {
kbr = 1;
}
@ -632,7 +632,7 @@ void Substance::set_TPp(double Temp, double Pressure)
}
v_here += dv;
if (dv == 0.0) {
throw TPX_Error("Substance::set_TPp","dv = 0 and no convergence");
throw CanteraError("Substance::set_TPp","dv = 0 and no convergence");
}
Set(PropertyPair::TV, Temp, v_here);
LoopCount++;