Replace Base::Exception with appropriate subclass

This commit is contained in:
wmayer
2018-11-14 19:27:52 +01:00
parent d478c3057b
commit 21d01fe6fc
7 changed files with 34 additions and 37 deletions

View File

@@ -439,7 +439,7 @@ void PropertyConstraintList::setPathValue(const ObjectIdentifier &path, const bo
int index = c0.getIndex();
if (c0.getIndex() >= _lValueList.size())
throw Base::Exception("Array out of bounds");
throw Base::IndexError("Array out of bounds");
switch (_lValueList[index]->Type) {
case Angle:
dvalue = Base::toRadians<double>(dvalue);
@@ -473,7 +473,7 @@ void PropertyConstraintList::setPathValue(const ObjectIdentifier &path, const bo
}
}
}
throw Base::Exception("Invalid constraint");
throw Base::ValueError("Invalid constraint");
}
const Constraint * PropertyConstraintList::getConstraint(const ObjectIdentifier &path) const
@@ -482,7 +482,7 @@ const Constraint * PropertyConstraintList::getConstraint(const ObjectIdentifier
if (c0.isArray() && path.numSubComponents() == 1) {
if (c0.getIndex() >= _lValueList.size())
throw Base::Exception("Array out of bounds");
throw Base::IndexError("Array out of bounds");
return _lValueList[c0.getIndex()];
}
@@ -494,7 +494,7 @@ const Constraint * PropertyConstraintList::getConstraint(const ObjectIdentifier
return *it;
}
}
throw Base::Exception("Invalid constraint");
throw Base::ValueError("Invalid constraint");
}
const boost::any PropertyConstraintList::getPathValue(const ObjectIdentifier &path) const
@@ -518,7 +518,7 @@ const ObjectIdentifier PropertyConstraintList::canonicalPath(const ObjectIdentif
if (c1.isSimple())
return p;
}
throw Base::Exception("Invalid constraint");
throw Base::ValueError("Invalid constraint");
}
void PropertyConstraintList::getPaths(std::vector<ObjectIdentifier> &paths) const

View File

@@ -1098,7 +1098,7 @@ int Sketch::checkGeoId(int geoId) const
if (geoId < 0)
geoId += Geoms.size();//convert negative external-geometry index to index into Geoms
if(!( geoId >= 0 && geoId < int(Geoms.size()) ))
throw Base::Exception("Sketch::checkGeoId. GeoId index out range.");
throw Base::IndexError("Sketch::checkGeoId. GeoId index out range.");
return geoId;
}
@@ -1140,7 +1140,7 @@ GCS::Curve* Sketch::getGCSCurveByGeoId(int geoId)
int Sketch::addConstraint(const Constraint *constraint)
{
if (Geoms.empty())
throw Base::Exception("Sketch::addConstraint. Can't add constraint to a sketch with no geometry!");
throw Base::ValueError("Sketch::addConstraint. Can't add constraint to a sketch with no geometry!");
int rtn = -1;
ConstrDef c;
@@ -2854,7 +2854,7 @@ double Sketch::calculateAngleViaPoint(int geoId1, int geoId2, double px, double
GCS::Curve* crv1 =getGCSCurveByGeoId(geoId1);
GCS::Curve* crv2 =getGCSCurveByGeoId(geoId2);
if (!crv1 || !crv2) {
throw Base::Exception("calculateAngleViaPoint: getGCSCurveByGeoId returned NULL!");
throw Base::ValueError("calculateAngleViaPoint: getGCSCurveByGeoId returned NULL!");
}
return GCSsys.calculateAngleViaPoint(*crv1, *crv2, p);
@@ -2871,7 +2871,7 @@ Base::Vector3d Sketch::calculateNormalAtPoint(int geoIdCurve, double px, double
//check pointers
GCS::Curve* crv = getGCSCurveByGeoId(geoIdCurve);
if (!crv) {
throw Base::Exception("calculateNormalAtPoint: getGCSCurveByGeoId returned NULL!\n");
throw Base::ValueError("calculateNormalAtPoint: getGCSCurveByGeoId returned NULL!\n");
}
double tx = 0.0, ty = 0.0;

View File

@@ -610,7 +610,7 @@ Base::Vector3d SketchObject::getPoint(int GeoId, PointPos PosId) const
{
if(!(GeoId == H_Axis || GeoId == V_Axis
|| (GeoId <= getHighestCurveIndex() && GeoId >= -getExternalGeometryCount()) ))
throw Base::Exception("SketchObject::getPoint. Invalid GeoId was supplied.");
throw Base::ValueError("SketchObject::getPoint. Invalid GeoId was supplied.");
const Part::Geometry *geo = getGeometry(GeoId);
if (geo->getTypeId() == Part::GeomPoint::getClassTypeId()) {
const Part::GeomPoint *p = static_cast<const Part::GeomPoint*>(geo);
@@ -1578,8 +1578,7 @@ int SketchObject::fillet(int GeoId1, int GeoId2,
radius = ((refp1 - normalintersect).Length() + (refp2 - normalintersect).Length())/2;
}
catch(Base::Exception e) {
catch(const Base::Exception&) {
radius = ref21.Length(); // fall-back to simplest estimation.
}
}
@@ -5609,8 +5608,7 @@ void SketchObject::rebuildExternalGeometry(void)
refSubShape = refShape.getSubShape(SubElement.c_str());
}
catch (Standard_Failure& e) {
throw Base::Exception(e.GetMessageString());
throw Base::CADKernelError(e.GetMessageString());
}
} else if (Obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
const App::Plane* pl = static_cast<const App::Plane*>(Obj);
@@ -5622,12 +5620,12 @@ void SketchObject::rebuildExternalGeometry(void)
gp_Pln plane(gp_Pnt(base.x,base.y,base.z), gp_Dir(normal.x, normal.y, normal.z));
BRepBuilderAPI_MakeFace fBuilder(plane);
if (!fBuilder.IsDone())
throw Base::Exception("Sketcher: addExternal(): Failed to build face from App::Plane");
throw Base::RuntimeError("Sketcher: addExternal(): Failed to build face from App::Plane");
TopoDS_Face f = TopoDS::Face(fBuilder.Shape());
refSubShape = f;
} else {
throw Base::Exception("Datum feature type is not yet supported as external geometry for a sketch");
throw Base::TypeError("Datum feature type is not yet supported as external geometry for a sketch");
}
switch (refSubShape.ShapeType())
@@ -5655,10 +5653,10 @@ void SketchObject::rebuildExternalGeometry(void)
}
} else {
throw Base::Exception("Selected external reference plane must be normal to sketch plane");
throw Base::ValueError("Selected external reference plane must be normal to sketch plane");
}
} else {
throw Base::Exception("Non-planar faces are not yet supported for external geometry of sketches");
throw Base::ValueError("Non-planar faces are not yet supported for external geometry of sketches");
}
}
break;
@@ -5704,7 +5702,7 @@ void SketchObject::rebuildExternalGeometry(void)
}
else {
// creates an ellipse
throw Base::Exception("Not yet supported geometry for external geometry");
throw Base::NotImplementedError("Not yet supported geometry for external geometry");
}
}
else {
@@ -5872,14 +5870,13 @@ void SketchObject::rebuildExternalGeometry(void)
}
}
else {
throw Base::Exception("Not yet supported geometry for external geometry");
throw Base::NotImplementedError("Not yet supported geometry for external geometry");
}
}
}
}
catch (Standard_Failure& e) {
throw Base::Exception(e.GetMessageString());
throw Base::CADKernelError(e.GetMessageString());
}
}
}
@@ -5898,7 +5895,7 @@ void SketchObject::rebuildExternalGeometry(void)
}
break;
default:
throw Base::Exception("Unknown type of geometry");
throw Base::TypeError("Unknown type of geometry");
break;
}
}
@@ -6422,7 +6419,7 @@ double SketchObject::calculateAngleViaPoint(int GeoId1, int GeoId2, double px, d
return sk.calculateAngleViaPoint(i1,i2,px,py);
}
else
throw Base::Exception("Null geometry in calculateAngleViaPoint");
throw Base::ValueError("Null geometry in calculateAngleViaPoint");
/*
// OCC-based calculation. It is faster, but it was removed due to problems
@@ -6436,12 +6433,12 @@ double SketchObject::calculateAngleViaPoint(int GeoId1, int GeoId2, double px, d
double u1 = 0.0;
double u2 = 0.0;
if (! g1.closestParameterToBasicCurve(p, u1) ) throw Base::Exception("SketchObject::calculateAngleViaPoint: closestParameter(curve1) failed!");
if (! g2.closestParameterToBasicCurve(p, u2) ) throw Base::Exception("SketchObject::calculateAngleViaPoint: closestParameter(curve2) failed!");
if (! g1.closestParameterToBasicCurve(p, u1) ) throw Base::ValueError("SketchObject::calculateAngleViaPoint: closestParameter(curve1) failed!");
if (! g2.closestParameterToBasicCurve(p, u2) ) throw Base::ValueError("SketchObject::calculateAngleViaPoint: closestParameter(curve2) failed!");
gp_Dir tan1, tan2;
if (! g1.tangent(u1,tan1) ) throw Base::Exception("SketchObject::calculateAngleViaPoint: tangent1 failed!");
if (! g2.tangent(u2,tan2) ) throw Base::Exception("SketchObject::calculateAngleViaPoint: tangent2 failed!");
if (! g1.tangent(u1,tan1) ) throw Base::ValueError("SketchObject::calculateAngleViaPoint: tangent1 failed!");
if (! g2.tangent(u2,tan2) ) throw Base::ValueError("SketchObject::calculateAngleViaPoint: tangent2 failed!");
assert(abs(tan1.Z())<0.0001);
assert(abs(tan2.Z())<0.0001);

View File

@@ -488,7 +488,7 @@ void CmdSketcherMapSketch::activated(int iMsg)
App::DocumentObject* part = static_cast<Part::Feature*>(selobjs[i].getObject());
if (!part) {
assert(0);
throw Base::Exception("Unexpected null pointer in CmdSketcherMapSketch::activated");
throw Base::ValueError("Unexpected null pointer in CmdSketcherMapSketch::activated");
}
std::vector<App::DocumentObject*> input = part->getOutList();
if (std::find(input.begin(), input.end(), &sketch) != input.end()) {

View File

@@ -652,7 +652,7 @@ void SketcherGui::makeTangentToArcOfParabolaviaNewPoint(Sketcher::SketchObject*
tryAutoRecompute(Obj);
}
std::string SketcherGui::getStrippedPythonExceptionString(const Base::Exception e)
std::string SketcherGui::getStrippedPythonExceptionString(const Base::Exception& e)
{
std::string msg = e.what();
@@ -7035,7 +7035,7 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg)
// only one sketch with its subelements are allowed to be selected
if (selection.size() != 1 || !selection[0].isObjectTypeOf(Sketcher::SketchObject::getClassTypeId())) {
strError = QObject::tr("Selected objects are not just geometry from one sketch.", dmbg);
throw(Base::Exception(""));
throw Base::ValueError("");
}
// get the needed lists and objects
@@ -7044,7 +7044,7 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg)
if (SubNames.size() != 3) {
strError = QObject::tr("Number of selected objects is not 3 (is %1).", dmbg).arg(SubNames.size());
throw(Base::Exception(""));
throw Base::ValueError("");
}
int GeoId1, GeoId2, GeoId3;
@@ -7066,14 +7066,14 @@ void CmdSketcherConstrainSnellsLaw::activated(int iMsg)
//a bunch of validity checks
if (areAllPointsOrSegmentsFixed(Obj, GeoId1, GeoId2, GeoId3) ) {
strError = QObject::tr("Can not create constraint with external geometry only!!", dmbg);
throw(Base::Exception(""));
throw Base::ValueError("");
}
if (!(isVertex(GeoId1,PosId1) && !isSimpleVertex(Obj, GeoId1, PosId1) &&
isVertex(GeoId2,PosId2) && !isSimpleVertex(Obj, GeoId2, PosId2) &&
isEdge(GeoId3,PosId3) )) {
strError = QObject::tr("Incompatible geometry is selected!", dmbg);
throw(Base::Exception(""));
throw Base::ValueError("");
};
const Part::Geometry *geo = Obj->getGeometry(GeoId3);

View File

@@ -105,7 +105,7 @@ void makeTangentToArcOfParabolaviaNewPoint(Sketcher::SketchObject* Obj,
int geoId2
);
std::string getStrippedPythonExceptionString(const Base::Exception);
std::string getStrippedPythonExceptionString(const Base::Exception&);
/// This function tries to auto-recompute the active document if the option
/// is set in the user parameter. If the option is not set nothing will be done

View File

@@ -6601,7 +6601,7 @@ public:
if (msg.Type == Gui::SelectionChanges::AddSelection) {
App::DocumentObject* obj = sketchgui->getObject()->getDocument()->getObject(msg.pObjectName);
if (obj == NULL)
throw Base::Exception("Sketcher: External geometry: Invalid object in selection");
throw Base::ValueError("Sketcher: External geometry: Invalid object in selection");
std::string subName(msg.pSubName);
if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) ||
obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()) ||
@@ -6826,7 +6826,7 @@ static const char *cursor_carboncopy[]={
if (msg.Type == Gui::SelectionChanges::AddSelection) {
App::DocumentObject* obj = sketchgui->getObject()->getDocument()->getObject(msg.pObjectName);
if (obj == NULL)
throw Base::Exception("Sketcher: Carbon Copy: Invalid object in selection");
throw Base::ValueError("Sketcher: Carbon Copy: Invalid object in selection");
if (obj->getTypeId() == Sketcher::SketchObject::getClassTypeId()) {