From 1647eee92ce9272c21eb772bdaef9fe78c3c54b0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 26 Nov 2018 14:15:19 +0100 Subject: [PATCH] add specialized exception type for bad graphs --- src/App/Application.cpp | 1 + src/App/Document.cpp | 2 +- src/App/DocumentObject.cpp | 8 ++++---- src/Base/Exception.cpp | 22 ++++++++++++++++++++++ src/Base/Exception.h | 17 +++++++++++++++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 4f282e5fa3..4b1a8c75b5 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1463,6 +1463,7 @@ void Application::initTypes(void) new ExceptionProducer; new ExceptionProducer; new ExceptionProducer; + new ExceptionProducer; new ExceptionProducer; new ExceptionProducer; new ExceptionProducer; diff --git a/src/App/Document.cpp b/src/App/Document.cpp index f91f464058..4ef87aab7b 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2040,7 +2040,7 @@ Document::getDependencyList(const std::vector& objs) const std::stringstream ss; ss << "Gathering all dependencies failed, probably due to circular dependencies. Error: "; ss << e.what(); - throw Base::RuntimeError(ss.str().c_str()); + throw Base::BadGraphError(ss.str().c_str()); } std::set out; diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 7c79ed223b..34f3675632 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -304,7 +304,7 @@ void _getInListRecursive(std::set& objSet, for (const auto objIt : obj->getInList()) { // if the check object is in the recursive inList we have a cycle! if (objIt == checkObj || depth <= 0) { - throw Base::RuntimeError("DocumentObject::getInListRecursive(): cyclic dependency detected!"); + throw Base::BadGraphError("DocumentObject::getInListRecursive(): cyclic dependency detected!"); } // if the element was already in the set then there is no need to process it again @@ -335,7 +335,7 @@ void _getOutListRecursive(std::set& objSet, for (const auto objIt : obj->getOutList()) { // if the check object is in the recursive inList we have a cycle! if (objIt == checkObj || depth <= 0) { - throw Base::RuntimeError("DocumentObject::getOutListRecursive(): cyclic dependency detected!"); + throw Base::BadGraphError("DocumentObject::getOutListRecursive(): cyclic dependency detected!"); } // if the element was already in the set then there is no need to process it again @@ -369,7 +369,7 @@ bool _isInInListRecursive(const DocumentObject* act, return true; // if we reach the depth limit we have a cycle! if (depth <= 0) { - throw Base::RuntimeError("DocumentObject::isInInListRecursive(): cyclic dependency detected!"); + throw Base::BadGraphError("DocumentObject::isInInListRecursive(): cyclic dependency detected!"); } if (_isInInListRecursive(obj, checkObj, depth - 1)) @@ -413,7 +413,7 @@ bool _isInOutListRecursive(const DocumentObject* act, return true; // if we reach the depth limit we have a cycle! if (depth <= 0) { - throw Base::RuntimeError("DocumentObject::isInOutListRecursive(): cyclic dependency detected!"); + throw Base::BadGraphError("DocumentObject::isInOutListRecursive(): cyclic dependency detected!"); } if (_isInOutListRecursive(obj, checkObj, depth - 1)) diff --git a/src/Base/Exception.cpp b/src/Base/Exception.cpp index 26a665d30e..de1ad2aca7 100644 --- a/src/Base/Exception.cpp +++ b/src/Base/Exception.cpp @@ -634,6 +634,28 @@ RuntimeError::RuntimeError(const RuntimeError &inst) // --------------------------------------------------------- +BadGraphError::BadGraphError() + : RuntimeError("The graph must be a DAG.") +{ +} + +BadGraphError::BadGraphError(const char * sMessage) + : RuntimeError(sMessage) +{ +} + +BadGraphError::BadGraphError(const std::string& sMessage) + : RuntimeError(sMessage) +{ +} + +BadGraphError::BadGraphError(const BadGraphError &inst) + : RuntimeError(inst) +{ +} + +// --------------------------------------------------------- + NotImplementedError::NotImplementedError() : Exception() { diff --git a/src/Base/Exception.h b/src/Base/Exception.h index e4b309e580..37b36c7427 100644 --- a/src/Base/Exception.h +++ b/src/Base/Exception.h @@ -468,6 +468,23 @@ public: virtual ~RuntimeError() throw() {} }; +/** + * The BadGraphError can be used to indicate that a graph is e.g. not a DAG. + * @author Werner Mayer + */ +class BaseExport BadGraphError : public RuntimeError +{ +public: + /// Construction + BadGraphError(); + BadGraphError(const char * sMessage); + BadGraphError(const std::string& sMessage); + /// Construction + BadGraphError(const BadGraphError &inst); + /// Destruction + virtual ~BadGraphError() throw() {} +}; + /** * The NotImplementedError can be used to indicate that an invoked function is not implemented. * @author Werner Mayer