Base: only handle Base::ParserError exceptions for quantity expressions
This commit is contained in:
@@ -96,7 +96,7 @@ Quantity::Quantity(double value, const QString& unit)
|
||||
this->_Unit = tmpQty.getUnit();
|
||||
this->_Value = value * tmpQty.getValue();
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
catch (const Base::ParserError&) {
|
||||
this->_Value = 0.0;
|
||||
this->_Unit = Unit();
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ int QuantityPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
try {
|
||||
*self = Quantity::parse(qstr);
|
||||
}
|
||||
catch(const Base::Exception& e) {
|
||||
catch(const Base::ParserError& e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return -1;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ int QuantityPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
try {
|
||||
*self = Quantity(f, unit);
|
||||
}
|
||||
catch(const Base::Exception& e) {
|
||||
catch(const Base::ParserError& e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ Unit::Unit(const QString& expr)
|
||||
try {
|
||||
*this = Quantity::parse(expr).getUnit();
|
||||
}
|
||||
catch (...) {
|
||||
catch (const Base::ParserError&) {
|
||||
Sig.Length = 0;
|
||||
Sig.Mass = 0;
|
||||
Sig.Time = 0;
|
||||
|
||||
@@ -90,8 +90,8 @@ int UnitPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
*self = Quantity::parse(qstr).getUnit();
|
||||
return 0;
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_RuntimeError, e.what());
|
||||
catch (const Base::ParserError& e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,13 +154,9 @@ PyObject* UnitsApi::sParseQuantity(PyObject * /*self*/, PyObject *args)
|
||||
try {
|
||||
rtn = Quantity::parse(qstr);
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
PyErr_Format(PyExc_IOError, "invalid unit expression \n");
|
||||
return 0L;
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
PyErr_Format(PyExc_IOError, "invalid unit expression \n");
|
||||
return 0L;
|
||||
catch (const Base::ParserError&) {
|
||||
PyErr_Format(PyExc_ValueError, "invalid unit expression \n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new QuantityPy(new Quantity(rtn));
|
||||
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
value = result.getValue();
|
||||
return true;
|
||||
}
|
||||
catch (Base::Exception&) {
|
||||
catch (Base::ParserError&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -631,7 +631,7 @@ void QuantitySpinBox::setUnitText(const QString& str)
|
||||
Base::Quantity quant = Base::Quantity::parse(str);
|
||||
setUnit(quant.getUnit());
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
catch (const Base::ParserError&) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user