Skip to content

Commit

Permalink
Base: only handle Base::ParserError exceptions for quantity expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 22, 2022
1 parent 945602f commit 88ded38
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Base/Quantity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Base/QuantityPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Base/UnitPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/Base/UnitsApiPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/QuantitySpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class QuantitySpinBoxPrivate
value = result.getValue();
return true;
}
catch (Base::Exception&) {
catch (Base::ParserError&) {
return false;
}
}
Expand Down Expand Up @@ -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&) {
}
}

Expand Down

0 comments on commit 88ded38

Please sign in to comment.