From e168634c725b72d453e45be230f952ab625dd373 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 11 Aug 2012 23:58:33 +0000 Subject: [PATCH] Translate exceptions into appropriate error codes in cvodes_rhs --- src/numerics/CVodesIntegrator.cpp | 33 ++++++++++++++++--------------- src/zeroD/ReactorNet.cpp | 20 +++++++------------ 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/numerics/CVodesIntegrator.cpp b/src/numerics/CVodesIntegrator.cpp index 2072f38e8..05b533e01 100644 --- a/src/numerics/CVodesIntegrator.cpp +++ b/src/numerics/CVodesIntegrator.cpp @@ -83,24 +83,25 @@ extern "C" { static int cvodes_rhs(realtype t, N_Vector y, N_Vector ydot, void* f_data) { - double* ydata = NV_DATA_S(y); //N_VDATA(y); - double* ydotdata = NV_DATA_S(ydot); //N_VDATA(ydot); - Cantera::FuncData* d = (Cantera::FuncData*)f_data; - Cantera::FuncEval* f = d->m_func; - //try { - if (d->m_pars.size() == 0) { - f->eval(t, ydata, ydotdata, NULL); - } else { - f->eval(t, ydata, ydotdata, DATA_PTR(d->m_pars)); + try { + double* ydata = NV_DATA_S(y); //N_VDATA(y); + double* ydotdata = NV_DATA_S(ydot); //N_VDATA(ydot); + Cantera::FuncData* d = (Cantera::FuncData*)f_data; + Cantera::FuncEval* f = d->m_func; + if (d->m_pars.size() == 0) { + f->eval(t, ydata, ydotdata, NULL); + } else { + f->eval(t, ydata, ydotdata, DATA_PTR(d->m_pars)); + } + } catch (Cantera::CanteraError& err) { + std::cerr << err.what() << std::endl; + return 1; // possibly recoverable error + } catch (...) { + std::cerr << "cvodes_rhs: unhandled exception" << std::endl; + return -1; // unrecoverable error } - //} - //catch (...) { - //Cantera::showErrors(); - //Cantera::error("Teminating execution"); - //} - return 0; + return 0; // successful evaluation } - } namespace Cantera diff --git a/src/zeroD/ReactorNet.cpp b/src/zeroD/ReactorNet.cpp index e12c463ae..ea309d55f 100644 --- a/src/zeroD/ReactorNet.cpp +++ b/src/zeroD/ReactorNet.cpp @@ -203,19 +203,13 @@ void ReactorNet::eval(doublereal t, doublereal* y, size_t n; size_t start = 0; size_t pstart = 0; - // use a try... catch block, since exceptions are not passed - // through CVODE, since it is C code - try { - updateState(y); - for (n = 0; n < m_nreactors; n++) { - m_reactors[n]->evalEqs(t, y + start, - ydot + start, p + pstart); - start += m_size[n]; - pstart += m_nparams[n]; - } - } catch (CanteraError& err) { - std::cerr << err.what() << std::endl; - error("Terminating execution."); + + updateState(y); + for (n = 0; n < m_nreactors; n++) { + m_reactors[n]->evalEqs(t, y + start, + ydot + start, p + pstart); + start += m_size[n]; + pstart += m_nparams[n]; } }