Skip to content

Commit

Permalink
use specialized exception classes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Apr 28, 2017
1 parent 0a32b91 commit 1673ab8
Show file tree
Hide file tree
Showing 60 changed files with 675 additions and 349 deletions.
46 changes: 23 additions & 23 deletions src/App/Application.cpp
Expand Up @@ -300,7 +300,7 @@ void Application::renameDocument(const char *OldName, const char *NewName)
signalRenameDocument(*temp);
}
else {
throw Base::Exception("Application::renameDocument(): no document with this name to rename!");
throw Base::RuntimeError("Application::renameDocument(): no document with this name to rename!");
}
}

Expand Down Expand Up @@ -449,7 +449,7 @@ Document* Application::openDocument(const char * FileName)
if (!File.exists()) {
std::stringstream str;
str << "File '" << FileName << "' does not exist!";
throw Base::Exception(str.str().c_str());
throw Base::FileSystemError(str.str().c_str());
}

// Before creating a new document we check whether the document is already open
Expand All @@ -460,7 +460,7 @@ Document* Application::openDocument(const char * FileName)
if (filepath == fi) {
std::stringstream str;
str << "The project '" << FileName << "' is already open!";
throw Base::Exception(str.str().c_str());
throw Base::FileSystemError(str.str().c_str());
}
}

Expand Down Expand Up @@ -534,7 +534,7 @@ void Application::setActiveDocument(const char *Name)
else {
std::stringstream s;
s << "Try to activate unknown document '" << Name << "'";
throw Base::Exception(s.str());
throw Base::RuntimeError(s.str());
}
}

Expand Down Expand Up @@ -649,7 +649,7 @@ Base::Reference<ParameterGrp> Application::GetParameterGroupByPath(const char*

// is there a path seperator ?
if (pos == std::string::npos) {
throw Base::Exception("Application::GetParameterGroupByPath() no parameter set name specified");
throw Base::ValueError("Application::GetParameterGroupByPath() no parameter set name specified");
}
// assigning the parameter set name
cTemp.assign(cName,0,pos);
Expand All @@ -658,7 +658,7 @@ Base::Reference<ParameterGrp> Application::GetParameterGroupByPath(const char*
// test if name is valid
std::map<std::string,ParameterManager *>::iterator It = mpcPramManager.find(cTemp.c_str());
if (It == mpcPramManager.end())
throw Base::Exception("Application::GetParameterGroupByPath() unknown parameter set name specified");
throw Base::ValueError("Application::GetParameterGroupByPath() unknown parameter set name specified");

return It->second->GetGroup(cName.c_str());
}
Expand Down Expand Up @@ -1070,13 +1070,13 @@ void segmentation_fault_handler(int sig)
case SIGSEGV:
std::cerr << "Illegal storage access..." << std::endl;
#if !defined(_DEBUG)
throw Base::Exception("Illegal storage access! Please save your work under a new file name and restart the application!");
throw Base::AccessViolation("Illegal storage access! Please save your work under a new file name and restart the application!");
#endif
break;
case SIGABRT:
std::cerr << "Abnormal program termination..." << std::endl;
#if !defined(_DEBUG)
throw Base::Exception("Break signal occoured");
throw Base::AbnormalProgramTermination("Break signal occoured");
#endif
break;
default:
Expand All @@ -1095,7 +1095,7 @@ void unexpection_error_handler()
std::cerr << "Unexpected error occurred..." << std::endl;
// try to throw an exception and give the user chance to save their work
#if !defined(_DEBUG)
throw Base::Exception("Unexpected error occurred! Please save your work under a new file name and restart the application!");
throw Base::AbnormalProgramTermination("Unexpected error occurred! Please save your work under a new file name and restart the application!");
#else
terminate();
#endif
Expand All @@ -1110,12 +1110,12 @@ void my_trans_func( unsigned int code, EXCEPTION_POINTERS* pExp )
//{
// case FLT_DIVIDE_BY_ZERO :
// //throw CMyFunkyDivideByZeroException(code, pExp);
// throw Base::Exception("Devision by zero!");
// throw Base::DivisionByZeroError("Devision by zero!");
// break;
//}

// general C++ SEH exception for things we don't need to handle separately....
throw Base::Exception("my_trans_func()");
throw Base::RuntimeError("my_trans_func()");
}
#endif
void Application::init(int argc, char ** argv)
Expand Down Expand Up @@ -2022,7 +2022,7 @@ void Application::ExtractUserPath()
// Default paths for the user specific stuff
struct passwd *pwd = getpwuid(getuid());
if (pwd == NULL)
throw Base::Exception("Getting HOME path from system failed!");
throw Base::RuntimeError("Getting HOME path from system failed!");
mConfig["UserHomePath"] = pwd->pw_dir;

char *path = pwd->pw_dir;
Expand All @@ -2040,7 +2040,7 @@ void Application::ExtractUserPath()
// This should never ever happen
std::stringstream str;
str << "Application data directory " << appData << " does not exist!";
throw Base::Exception(str.str());
throw Base::FileSystemError(str.str());
}

// In order to write into our data path, we must create some directories, first.
Expand All @@ -2057,7 +2057,7 @@ void Application::ExtractUserPath()
error += appData;
// Want more details on console
std::cerr << error << std::endl;
throw Base::Exception(error);
throw Base::FileSystemError(error);
}
}
appData += PATHSEP;
Expand All @@ -2071,7 +2071,7 @@ void Application::ExtractUserPath()
error += appData;
// Want more details on console
std::cerr << error << std::endl;
throw Base::Exception(error);
throw Base::FileSystemError(error);
}
}

Expand All @@ -2084,7 +2084,7 @@ void Application::ExtractUserPath()
// Default paths for the user specific stuff on the platform
struct passwd *pwd = getpwuid(getuid());
if (pwd == NULL)
throw Base::Exception("Getting HOME path from system failed!");
throw Base::RuntimeError("Getting HOME path from system failed!");
mConfig["UserHomePath"] = pwd->pw_dir;
std::string appData = pwd->pw_dir;
appData += PATHSEP;
Expand All @@ -2096,7 +2096,7 @@ void Application::ExtractUserPath()
// This should never ever happen
std::stringstream str;
str << "Application data directory " << appData << " does not exist!";
throw Base::Exception(str.str());
throw Base::FileSystemError(str.str());
}

// In order to write to our data path, we must create some directories, first.
Expand All @@ -2112,7 +2112,7 @@ void Application::ExtractUserPath()
error += appData;
// Want more details on console
std::cerr << error << std::endl;
throw Base::Exception(error);
throw Base::FileSystemError(error);
}
}
appData += PATHSEP;
Expand All @@ -2126,7 +2126,7 @@ void Application::ExtractUserPath()
error += appData;
// Want more details on console
std::cerr << error << std::endl;
throw Base::Exception(error);
throw Base::FileSystemError(error);
}
}

Expand Down Expand Up @@ -2161,7 +2161,7 @@ void Application::ExtractUserPath()
// This should never ever happen
std::stringstream str;
str << "Application data directory " << appData << " does not exist!";
throw Base::Exception(str.str());
throw Base::FileSystemError(str.str());
}

// In order to write to our data path we must create some directories first.
Expand All @@ -2177,7 +2177,7 @@ void Application::ExtractUserPath()
error += appData;
// Want more details on console
std::cerr << error << std::endl;
throw Base::Exception(error);
throw Base::FileSystemError(error);
}
}
}
Expand All @@ -2191,7 +2191,7 @@ void Application::ExtractUserPath()
error += appData;
// Want more details on console
std::cerr << error << std::endl;
throw Base::Exception(error);
throw Base::FileSystemError(error);
}
}

Expand Down Expand Up @@ -2260,7 +2260,7 @@ std::string Application::FindHomePath(const char* sCall)
int nchars = readlink("/proc/self/exe", resolved, PATH_MAX);
#endif
if (nchars < 0 || nchars >= PATH_MAX)
throw Base::Exception("Cannot determine the absolute path of the executable");
throw Base::FileSystemError("Cannot determine the absolute path of the executable");
resolved[nchars] = '\0'; // enfore null termination
absPath = resolved;
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/Document.cpp
Expand Up @@ -1747,7 +1747,7 @@ Document::getDependencyList(const std::vector<App::DocumentObject*>& objs) const
std::stringstream ss;
ss << "Gathering all dependencies failed, probably due to circular dependencies. Error: ";
ss << e.what();
throw Base::Exception(ss.str().c_str());
throw Base::RuntimeError(ss.str().c_str());
}

std::set<Vertex> out;
Expand Down
10 changes: 5 additions & 5 deletions src/App/DocumentObject.cpp
Expand Up @@ -207,7 +207,7 @@ void _getInListRecursive(std::vector<DocumentObject*>& objSet, const DocumentObj
// if the check object is in the recursive inList we have a cycle!
if (objIt == checkObj || depth <= 0){
std::cerr << "DocumentObject::getInListRecursive(): cyclic dependency detected!"<<std::endl;
throw Base::Exception("DocumentObject::getInListRecursive(): cyclic dependency detected!");
throw Base::RuntimeError("DocumentObject::getInListRecursive(): cyclic dependency detected!");
}

objSet.push_back(objIt);
Expand Down Expand Up @@ -239,7 +239,7 @@ void _getOutListRecursive(std::vector<DocumentObject*>& objSet, const DocumentOb
// if the check object is in the recursive inList we have a cycle!
if (objIt == checkObj || depth <= 0){
std::cerr << "DocumentObject::getOutListRecursive(): cyclic dependency detected!" << std::endl;
throw Base::Exception("DocumentObject::getOutListRecursive(): cyclic dependency detected!");
throw Base::RuntimeError("DocumentObject::getOutListRecursive(): cyclic dependency detected!");
}
objSet.push_back(objIt);
_getOutListRecursive(objSet, objIt, checkObj,depth-1);
Expand Down Expand Up @@ -280,7 +280,7 @@ bool DocumentObject::testIfLinkDAGCompatible(const std::vector<DocumentObject *>
{
Document* doc = this->getDocument();
if (!doc)
throw Base::Exception("DocumentObject::testIfLinkIsDAG: object is not in any document.");
throw Base::RuntimeError("DocumentObject::testIfLinkIsDAG: object is not in any document.");
std::vector<App::DocumentObject*> deplist = doc->getDependencyList(linksTo);
if( std::find(deplist.begin(),deplist.end(),this) != deplist.end() )
//found this in dependency list
Expand Down Expand Up @@ -315,7 +315,7 @@ bool DocumentObject::_isInInListRecursive(const DocumentObject* /*act*/,
// if the check object is in the recursive inList we have a cycle!
if (obj == checkObj || depth <= 0){
std::cerr << "DocumentObject::getOutListRecursive(): cyclic dependency detected!" << std::endl;
throw Base::Exception("DocumentObject::getOutListRecursive(): cyclic dependency detected!");
throw Base::RuntimeError("DocumentObject::getOutListRecursive(): cyclic dependency detected!");
}

if (_isInInListRecursive(obj, test, checkObj, depth - 1))
Expand Down Expand Up @@ -362,7 +362,7 @@ bool DocumentObject::_isInOutListRecursive(const DocumentObject* act,
// if the check object is in the recursive inList we have a cycle!
if (obj == checkObj || depth <= 0){
std::cerr << "DocumentObject::isInOutListRecursive(): cyclic dependency detected!" << std::endl;
throw Base::Exception("DocumentObject::isInOutListRecursive(): cyclic dependency detected!");
throw Base::RuntimeError("DocumentObject::isInOutListRecursive(): cyclic dependency detected!");
}

if (_isInOutListRecursive(obj, test, checkObj, depth - 1))
Expand Down
4 changes: 3 additions & 1 deletion src/App/DocumentPyImp.cpp
Expand Up @@ -611,7 +611,9 @@ PyObject* DocumentPy::getTempFileName(PyObject *args)
fileName.deleteFile();

PyObject *p = PyUnicode_DecodeUTF8(fileName.filePath().c_str(),fileName.filePath().size(),0);
if (!p) throw Base::Exception("UTF8 conversion failure at PropertyString::getPyObject()");
if (!p) {
throw Base::UnicodeError("UTF8 conversion failure at PropertyString::getPyObject()");
}
return p;
}

Expand Down
2 changes: 1 addition & 1 deletion src/App/DynamicProperty.cpp
Expand Up @@ -241,7 +241,7 @@ Property* DynamicProperty::addDynamicProperty(const char* type, const char* name
delete base;
std::stringstream str;
str << "'" << type << "' is not a property type";
throw Base::Exception(str.str());
throw Base::ValueError(str.str());
}

// get unique name
Expand Down
4 changes: 2 additions & 2 deletions src/App/Expression.cpp
Expand Up @@ -1715,9 +1715,9 @@ double num_change(char* yytext,char dez_delim,char grp_delim)
errno = 0;
ret_val = strtod( temp, NULL );
if (ret_val == 0 && errno == ERANGE)
throw Base::Exception("Number underflow.");
throw Base::UnderflowError("Number underflow.");
if (ret_val == HUGE_VAL || ret_val == -HUGE_VAL)
throw Base::Exception("Number overflow.");
throw Base::OverflowError("Number overflow.");

return ret_val;
}
Expand Down
4 changes: 2 additions & 2 deletions src/App/ExpressionParser.l
Expand Up @@ -251,9 +251,9 @@ EXPO [eE][-+]?[0-9]+
{DIGIT}+ { COUNTCHARS;
yylval.ivalue = strtoll( yytext, NULL, 0 );
if (yylval.ivalue == LLONG_MIN)
throw Base::Exception("Integer underflow");
throw Base::UnderflowError("Integer underflow");
else if (yylval.ivalue == LLONG_MAX)
throw Base::Exception("Integer overflow");
throw Base::OverflowError("Integer overflow");
if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER;
}

Expand Down
6 changes: 3 additions & 3 deletions src/App/Extension.cpp
Expand Up @@ -75,13 +75,13 @@ void Extension::initExtensionType(Base::Type type) {

m_extensionType = type;
if(m_extensionType.isBad())
throw Base::Exception("Extension: Extension type not set");
throw Base::RuntimeError("Extension: Extension type not set");
}

void Extension::initExtension(ExtensionContainer* obj) {

if(m_extensionType.isBad())
throw Base::Exception("Extension: Extension type not set");
throw Base::RuntimeError("Extension: Extension type not set");

//all properties are initialised without PropertyContainer father. Now that we know it we can
//finally finish the property initialisation
Expand All @@ -108,7 +108,7 @@ PyObject* Extension::getExtensionPyObject(void) {
std::string Extension::name() const {

if(m_extensionType.isBad())
throw Base::Exception("Extension::name: Extension type not set");
throw Base::RuntimeError("Extension::name: Extension type not set");

std::string temp(m_extensionType.getName());
std::string::size_type pos = temp.find_last_of(":");
Expand Down
8 changes: 4 additions & 4 deletions src/App/ExtensionContainer.cpp
Expand Up @@ -53,7 +53,7 @@ ExtensionContainer::~ExtensionContainer() {
void ExtensionContainer::registerExtension(Base::Type extension, Extension* ext) {

if(ext->getExtendedContainer() != this)
throw Base::Exception("ExtensionContainer::registerExtension: Extension has not this as base object");
throw Base::ValueError("ExtensionContainer::registerExtension: Extension has not this as base object");

//no duplicate extensions (including base classes)
if(hasExtension(extension)) {
Expand Down Expand Up @@ -104,7 +104,7 @@ Extension* ExtensionContainer::getExtension(Base::Type t) {
return entry.second;
}
//if we arive hear we don't have anything matching
throw Base::Exception("ExtensionContainer::getExtension: No extension of given type available");
throw Base::TypeError("ExtensionContainer::getExtension: No extension of given type available");
}

return result->second;
Expand Down Expand Up @@ -370,7 +370,7 @@ void ExtensionContainer::restoreExtensions(Base::XMLReader& reader) {
if (extension.isBad() || !extension.isDerivedFrom(App::Extension::getExtensionClassTypeId())) {
std::stringstream str;
str << "No extension found of type '" << Type << "'" << std::ends;
throw Base::Exception(str.str());
throw Base::TypeError(str.str());
}

//register the extension
Expand All @@ -380,7 +380,7 @@ void ExtensionContainer::restoreExtensions(Base::XMLReader& reader) {
delete ext;
std::stringstream str;
str << "Extension is not a python addable version: '" << Type << "'" << std::ends;
throw Base::Exception(str.str());
throw Base::TypeError(str.str());
}

ext->initExtension(this);
Expand Down
4 changes: 2 additions & 2 deletions src/App/FeatureTest.cpp
Expand Up @@ -134,7 +134,7 @@ DocumentObjectExecReturn *FeatureTest::execute(void)
{
case 0: break;
case 1: throw "Test Exeption";
case 2: throw Base::Exception("FeatureTestException::execute(): Testexception");
case 2: throw Base::RuntimeError("FeatureTestException::execute(): Testexception");
case 3: *i=0;printf("%i",*i);break; // seg-vault
case 4: j=0; printf("%i",1/j); break; // int devision by zero
case 5: f=0.0; printf("%f",1/f); break; // float devision by zero
Expand All @@ -161,7 +161,7 @@ DocumentObjectExecReturn *FeatureTestException::execute(void)
{
//ExceptionType;

throw Base::Exception("FeatureTestException::execute(): Testexception ;-)");
throw Base::RuntimeError("FeatureTestException::execute(): Testexception ;-)");

return 0;
}
4 changes: 2 additions & 2 deletions src/App/GeoFeatureGroupExtension.cpp
Expand Up @@ -55,15 +55,15 @@ GeoFeatureGroupExtension::~GeoFeatureGroupExtension(void)
void GeoFeatureGroupExtension::initExtension(ExtensionContainer* obj) {

if(!obj->isDerivedFrom(App::GeoFeature::getClassTypeId()))
throw Base::Exception("GeoFeatureGroupExtension can only be applied to GeoFeatures");
throw Base::RuntimeError("GeoFeatureGroupExtension can only be applied to GeoFeatures");

App::GroupExtension::initExtension(obj);
}

PropertyPlacement& GeoFeatureGroupExtension::placement() {

if(!getExtendedContainer())
throw Base::Exception("GeoFeatureGroupExtension was not applied to GeoFeature");
throw Base::RuntimeError("GeoFeatureGroupExtension was not applied to GeoFeature");

return static_cast<App::GeoFeature*>(getExtendedContainer())->Placement;
}
Expand Down

0 comments on commit 1673ab8

Please sign in to comment.