From 28bcf816264d2fa44803ec30abdfb3c88ec3749c Mon Sep 17 00:00:00 2001 From: titiger Date: Wed, 30 Nov 2016 22:33:41 +0100 Subject: [PATCH] Error handling --- source/glest_game/types/resource_type.cpp | 4 ++++ source/glest_game/types/skill_type.cpp | 7 +++---- source/glest_game/types/upgrade_type.cpp | 6 +++++- source/glest_game/world/tileset.cpp | 12 ++++++++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/source/glest_game/types/resource_type.cpp b/source/glest_game/types/resource_type.cpp index d90543d4..a3b3b9bd 100644 --- a/source/glest_game/types/resource_type.cpp +++ b/source/glest_game/types/resource_type.cpp @@ -186,6 +186,10 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre displayInHud=true; } } + catch(megaglest_runtime_error& ex) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + throw megaglest_runtime_error("Error loading resource type: "+ path + "\nMessage: " + ex.what(),!ex.wantStackTrace()); + } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); throw megaglest_runtime_error("Error loading resource type: " + path + "\n" + e.what()); diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index ef13f41e..803dd61a 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -482,13 +482,12 @@ void SkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode, animationAttributes.push_back(animationAttributeList); } else { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] WARNING CANNOT LOAD MODEL [%s] for parentLoader [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),parentLoader.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] ERROR CANNOT LOAD MODEL [%s] for parentLoader [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),parentLoader.c_str()); + throw megaglest_runtime_error("Error: cannot load model ["+path+"] for skill ["+name+"] ",true); } } if(animations.empty() == true) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"Error no animations found for skill [%s] for parentLoader [%s]",name.c_str(),parentLoader.c_str()); - throw megaglest_runtime_error(szBuf,true); + throw megaglest_runtime_error("Error no animations found for skill ["+name+"] for parentLoader ["+parentLoader+"]",true); } } diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 7529a458..1a1f3b6b 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -1057,9 +1057,13 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, //values UpgradeTypeBase::load(upgradeNode,name); } + catch(megaglest_runtime_error& ex) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + throw megaglest_runtime_error("Error loading UpgradeType: "+ currentPath + "\nMessage: " + ex.what(),!ex.wantStackTrace() ); + } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - throw megaglest_runtime_error("Error loading UpgradeType: "+ dir + "\n" +e.what()); + throw megaglest_runtime_error("Error loading UpgradeType: "+ currentPath + "\n" +e.what()); } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index 65595e2d..5721d308 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -136,7 +136,7 @@ Checksum Tileset::loadTileset(const vector pathList, const string &tiles } } if(found == false) { - throw megaglest_runtime_error("Error could not find tileset [" + tilesetName + "]\n"); + throw megaglest_runtime_error("Error could not find tileset [" + tilesetName + "]\n",true); } return tilesetChecksum; @@ -251,6 +251,10 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck width = pixmap->getW(); height = pixmap->getW(); } + catch(megaglest_runtime_error& ex) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + throw megaglest_runtime_error("Error loading tileset: "+ path + "\nMessage: " + ex.what(),!ex.wantStackTrace() ); + } catch(const exception &ex) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); @@ -491,7 +495,11 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck } //Exception handling (conversions and so on); - catch(const exception &e) { + catch(megaglest_runtime_error& ex) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + throw megaglest_runtime_error("Error loading tileset: "+ path + "\nMessage: " + ex.what(),!ex.wantStackTrace() ); + } + catch(const exception &e) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); throw megaglest_runtime_error("Error: " + path + "\n" + e.what()); }