diff --git a/src/App/Document.cpp b/src/App/Document.cpp index e6f980aad4..46da8b9d40 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1092,8 +1092,13 @@ Document::~Document() doc->setInvalid(); // remove Transient directory - Base::FileInfo TransDir(TransientDir.getValue()); - TransDir.deleteDirectoryRecursive(); + try { + Base::FileInfo TransDir(TransientDir.getValue()); + TransDir.deleteDirectoryRecursive(); + } + catch (const Base::Exception& e) { + std::cerr << "Removing transient directory failed: " << e.what() << std::endl; + } delete d; } diff --git a/src/Base/Handle.cpp b/src/Base/Handle.cpp index 1827da7072..f8ba0982bb 100644 --- a/src/Base/Handle.cpp +++ b/src/Base/Handle.cpp @@ -26,6 +26,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include #endif @@ -47,7 +48,7 @@ Handled::Handled() Handled::~Handled() { if ((int)(*_lRefCount) != 0) - throw Exception("Reference counter of deleted object is not zero!!!!!\n"); + std::cerr << "Reference counter of deleted object is not zero!!!!!" << std::endl; delete _lRefCount; } diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index e4b7719e17..20951fb724 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -635,7 +635,7 @@ RecentFilesAction::RecentFilesAction ( Command* pcCmd, QObject * parent ) RecentFilesAction::~RecentFilesAction() { - save(); + try { save(); } catch (...) {} } /** Adds the new item to the recent files. */ diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 83dbb250c7..cbd7d4db20 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -29,6 +29,7 @@ # include # include # include +# include # include # include # include @@ -385,7 +386,12 @@ Application::~Application() } // save macros - MacroCommand::save(); + try { + MacroCommand::save(); + } + catch (const Base::Exception& e) { + std::cerr << "Saving macros failed: " << e.what() << std::endl; + } //App::GetApplication().Detach(this); delete d; diff --git a/src/Gui/PrefWidgets.cpp b/src/Gui/PrefWidgets.cpp index a946a1245c..c5750981a4 100644 --- a/src/Gui/PrefWidgets.cpp +++ b/src/Gui/PrefWidgets.cpp @@ -28,6 +28,7 @@ #endif #include +#include #include #include "PrefWidgets.h" @@ -557,19 +558,24 @@ void PrefQuantitySpinBox::pushToHistory(const QString &valueq) std::string value(val.toUtf8()); if (d->handle.isValid()) { - // do nothing if the given value is on top of the history - std::string tHist = d->handle->GetASCII("Hist0"); - if (tHist != val.toUtf8().constData()) { - for (int i = d->historySize -1 ; i>=0 ;i--) { - QByteArray hist1 = "Hist"; - QByteArray hist0 = "Hist"; - hist1.append(QByteArray::number(i+1)); - hist0.append(QByteArray::number(i)); - std::string tHist = d->handle->GetASCII(hist0); - if (!tHist.empty()) - d->handle->SetASCII(hist1,tHist.c_str()); + try { + // do nothing if the given value is on top of the history + std::string tHist = d->handle->GetASCII("Hist0"); + if (tHist != val.toUtf8().constData()) { + for (int i = d->historySize -1 ; i>=0 ;i--) { + QByteArray hist1 = "Hist"; + QByteArray hist0 = "Hist"; + hist1.append(QByteArray::number(i+1)); + hist0.append(QByteArray::number(i)); + std::string tHist = d->handle->GetASCII(hist0); + if (!tHist.empty()) + d->handle->SetASCII(hist1,tHist.c_str()); + } + d->handle->SetASCII("Hist0",value.c_str()); } - d->handle->SetASCII("Hist0",value.c_str()); + } + catch (const Base::Exception& e) { + Console().Warning("pushToHistory: %s\n", e.what()); } } } diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index 027077bfb9..a794b465c5 100644 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -107,11 +107,15 @@ FemMesh::~FemMesh() { //Base::Console().Log("FemMesh::~FemMesh():%p\n",this); - TopoDS_Shape aNull; - myMesh->ShapeToMesh(aNull); - myMesh->Clear(); - //myMesh->ClearLog(); - delete myMesh; + try { + TopoDS_Shape aNull; + myMesh->ShapeToMesh(aNull); + myMesh->Clear(); + //myMesh->ClearLog(); + delete myMesh; + } + catch (...) { + } } FemMesh &FemMesh::operator=(const FemMesh& mesh) diff --git a/src/Mod/Mesh/App/Exporter.cpp b/src/Mod/Mesh/App/Exporter.cpp index b769082b66..7c91949c5e 100644 --- a/src/Mod/Mesh/App/Exporter.cpp +++ b/src/Mod/Mesh/App/Exporter.cpp @@ -112,7 +112,12 @@ MergeExporter::~MergeExporter() } } - mergingMesh.save(fName.c_str()); + try { + mergingMesh.save(fName.c_str()); + } + catch (const Base::Exception& e) { + std::cerr << "Saving mesh failed: " << e.what() << std::endl; + } } diff --git a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp index 48791e67a2..1ba8063f5c 100644 --- a/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp +++ b/src/Mod/Mesh/Gui/DlgEvaluateMeshImp.cpp @@ -168,11 +168,15 @@ DlgEvaluateMeshImp::~DlgEvaluateMeshImp() delete it->second; } - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Mod/Mesh/Evaluation"); - hGrp->SetBool("CheckNonManifoldPoints", d->checkNonManfoldPoints); - hGrp->SetBool("EnableFoldsCheck", d->enableFoldsCheck); - hGrp->SetBool("StrictlyDegenerated", d->strictlyDegenerated); + try { + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Mod/Mesh/Evaluation"); + hGrp->SetBool("CheckNonManifoldPoints", d->checkNonManfoldPoints); + hGrp->SetBool("EnableFoldsCheck", d->enableFoldsCheck); + hGrp->SetBool("StrictlyDegenerated", d->strictlyDegenerated); + } + catch (...) { + } d->vp.clear(); delete d; diff --git a/src/Mod/Part/Gui/TaskAttacher.cpp b/src/Mod/Part/Gui/TaskAttacher.cpp index 51557089e4..cf482671aa 100644 --- a/src/Mod/Part/Gui/TaskAttacher.cpp +++ b/src/Mod/Part/Gui/TaskAttacher.cpp @@ -876,7 +876,7 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing) ).toLatin1(); Base::Interpreter().runString(code_2.constData()); } - catch (Base::PyException &e){ + catch (Base::Exception &e){ e.ReportException(); } } @@ -884,7 +884,7 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing) try { Base::Interpreter().runString("del(tv)"); } - catch (Base::PyException &e) { + catch (Base::Exception &e) { e.ReportException(); } } diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index e00eeafc73..02da50f264 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -224,55 +224,61 @@ std::vector TaskFeaturePick::buildFeatures() { int index = 0; std::vector result; - auto activeBody = PartDesignGui::getBody(false); - if (!activeBody) - return result; - auto activePart = PartDesignGui::getPartFor(activeBody, false); + try { + auto activeBody = PartDesignGui::getBody(false); + if (!activeBody) + return result; - for (std::vector::const_iterator st = statuses.begin(); st != statuses.end(); st++) { - QListWidgetItem* item = ui->listWidget->item(index); + auto activePart = PartDesignGui::getPartFor(activeBody, false); - if (item->isSelected() && !item->isHidden()) { - QString t = item->data(Qt::UserRole).toString(); - auto obj = App::GetApplication().getDocument(documentName.c_str())->getObject(t.toLatin1().data()); + for (std::vector::const_iterator st = statuses.begin(); st != statuses.end(); st++) { + QListWidgetItem* item = ui->listWidget->item(index); - //build the dependend copy or reference if wanted by the user - if (*st == otherBody || *st == otherPart || *st == notInBody) { - if (!ui->radioXRef->isChecked()) { - auto copy = makeCopy(obj, "", ui->radioIndependent->isChecked()); + if (item->isSelected() && !item->isHidden()) { + QString t = item->data(Qt::UserRole).toString(); + auto obj = App::GetApplication().getDocument(documentName.c_str())->getObject(t.toLatin1().data()); - if (*st == otherBody) { - activeBody->addObject(copy); - } - else if (*st == otherPart) { - auto oBody = PartDesignGui::getBodyFor(obj, false); - if (!oBody) - activePart->addObject(copy); - else + //build the dependend copy or reference if wanted by the user + if (*st == otherBody || *st == otherPart || *st == notInBody) { + if (!ui->radioXRef->isChecked()) { + auto copy = makeCopy(obj, "", ui->radioIndependent->isChecked()); + + if (*st == otherBody) { activeBody->addObject(copy); - } - else if (*st == notInBody) { - activeBody->addObject(copy); - // doesn't supposed to get here anything but sketch but to be on the safe side better to check - if (copy->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) { - Sketcher::SketchObject *sketch = static_cast(copy); - PartDesignGui::fixSketchSupport(sketch); } + else if (*st == otherPart) { + auto oBody = PartDesignGui::getBodyFor(obj, false); + if (!oBody) + activePart->addObject(copy); + else + activeBody->addObject(copy); + } + else if (*st == notInBody) { + activeBody->addObject(copy); + // doesn't supposed to get here anything but sketch but to be on the safe side better to check + if (copy->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) { + Sketcher::SketchObject *sketch = static_cast(copy); + PartDesignGui::fixSketchSupport(sketch); + } + } + result.push_back(copy); + } + else { + result.push_back(obj); } - result.push_back(copy); } else { result.push_back(obj); } - } - else { - result.push_back(obj); + + break; } - break; + index++; } - - index++; + } + catch (const Base::Exception& e) { + e.ReportException(); } return result; @@ -499,7 +505,7 @@ TaskDlgFeaturePick::~TaskDlgFeaturePick() } Content.clear(); - abortFunction(); + try { abortFunction(); } catch (...) {} } } diff --git a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp index 485c53eec6..192f314de6 100644 --- a/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLinearPatternParameters.cpp @@ -372,20 +372,20 @@ unsigned TaskLinearPatternParameters::getOccurrences(void) const TaskLinearPatternParameters::~TaskLinearPatternParameters() { - //hide the parts coordinate system axis for selection - PartDesign::Body * body = PartDesign::Body::findBodyOf(getObject()); - if (body) { - try { + try { + //hide the parts coordinate system axis for selection + PartDesign::Body * body = PartDesign::Body::findBodyOf(getObject()); + if (body) { App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); } - catch (const Base::Exception &ex) { - Base::Console().Error ("%s\n", ex.what () ); - } } - + catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); + } + delete ui; if (proxy) delete proxy; diff --git a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp index 8eb7fccd32..084ab353c3 100644 --- a/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMirroredParameters.cpp @@ -287,16 +287,16 @@ void TaskMirroredParameters::apply() TaskMirroredParameters::~TaskMirroredParameters() { //hide the parts coordinate system axis for selection - PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); - if ( body ) { - try { + try { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); + if ( body ) { App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); - } catch (const Base::Exception &ex) { - Base::Console().Error ("%s\n", ex.what () ); } + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); } delete ui; diff --git a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp index b3e8755028..874273f63e 100644 --- a/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPolarPatternParameters.cpp @@ -375,16 +375,16 @@ unsigned TaskPolarPatternParameters::getOccurrences(void) const TaskPolarPatternParameters::~TaskPolarPatternParameters() { //hide the parts coordinate system axis for selection - PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); - if ( body ) { - try { + try { + PartDesign::Body * body = PartDesign::Body::findBodyOf ( getObject() ); + if ( body ) { App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility (); - } catch (const Base::Exception &ex) { - Base::Console().Error ("%s\n", ex.what () ); } + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); } delete ui; diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp index 7497dfa440..ff8b2c7d18 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -245,16 +245,16 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) TaskBoxPrimitives::~TaskBoxPrimitives() { //hide the parts coordinate system axis for selection - PartDesign::Body * body = vp ? PartDesign::Body::findBodyOf(vp->getObject()) : 0; - if (body) { - try { + try { + PartDesign::Body * body = vp ? PartDesign::Body::findBodyOf(vp->getObject()) : 0; + if (body) { App::Origin *origin = body->getOrigin(); Gui::ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); - } catch (const Base::Exception &ex) { - Base::Console().Error ("%s\n", ex.what () ); } + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); } } diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index ff0fe28a9b..b42587e5fe 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -360,17 +360,17 @@ bool TaskRevolutionParameters::getReversed(void) const TaskRevolutionParameters::~TaskRevolutionParameters() { - //hide the parts coordinate system axis for selection - PartDesign::Body * body = vp ? PartDesign::Body::findBodyOf(vp->getObject()) : 0; - if (body) { - try { + try { + //hide the parts coordinate system axis for selection + PartDesign::Body * body = vp ? PartDesign::Body::findBodyOf(vp->getObject()) : 0; + if (body) { App::Origin *origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); - } catch (const Base::Exception &ex) { - Base::Console().Error ("%s\n", ex.what () ); } + } catch (const Base::Exception &ex) { + Base::Console().Error ("%s\n", ex.what () ); } delete ui; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 7df2d79156..a74896bba6 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -308,10 +308,14 @@ TaskSketcherElements::TaskSketcherElements(ViewProviderSketch *sketchView) TaskSketcherElements::~TaskSketcherElements() { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/Elements"); - hGrp->SetBool("Auto-switch to edge", ui->autoSwitchBox->isChecked()); - hGrp->SetBool("Extended Naming", ui->namingBox->isChecked()); - + try { + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/Elements"); + hGrp->SetBool("Auto-switch to edge", ui->autoSwitchBox->isChecked()); + hGrp->SetBool("Extended Naming", ui->namingBox->isChecked()); + } + catch (const Base::Exception&) { + } + connectionElementsChanged.disconnect(); delete ui; }