mirror of
https://github.com/glest/glest-source.git
synced 2025-10-01 18:06:44 +02:00
- added support for throwing known errors and skipping stack traces (For friendlier error messages)
This commit is contained in:
@@ -918,6 +918,23 @@ void Game::init(bool initForPreviewOnly) {
|
|||||||
try {
|
try {
|
||||||
world.init(this, gameSettings.getDefaultUnits());
|
world.init(this, gameSettings.getDefaultUnits());
|
||||||
}
|
}
|
||||||
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
string sErrBuf = "";
|
||||||
|
if(ex.wantStackTrace() == true) {
|
||||||
|
char szErrBuf[8096]="";
|
||||||
|
sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sErrBuf = ex.what();
|
||||||
|
}
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str());
|
||||||
|
|
||||||
|
if(errorMessageBox.getEnabled() == false) {
|
||||||
|
ErrorDisplayMessage(ex.what(),true);
|
||||||
|
}
|
||||||
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
char szErrBuf[8096]="";
|
char szErrBuf[8096]="";
|
||||||
sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
|
sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
@@ -259,6 +259,7 @@ void World::init(Game *game, bool createUnits, bool initFactions){
|
|||||||
initMinimap();
|
initMinimap();
|
||||||
|
|
||||||
bool gotError = false;
|
bool gotError = false;
|
||||||
|
bool skipStackTrace = false;
|
||||||
string sErrBuf = "";
|
string sErrBuf = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -266,6 +267,19 @@ void World::init(Game *game, bool createUnits, bool initFactions){
|
|||||||
initUnits();
|
initUnits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
gotError = true;
|
||||||
|
if(ex.wantStackTrace() == true) {
|
||||||
|
char szErrBuf[8096]="";
|
||||||
|
sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipStackTrace = true;
|
||||||
|
sErrBuf = ex.what();
|
||||||
|
}
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
|
||||||
|
}
|
||||||
catch(const std::exception &ex) {
|
catch(const std::exception &ex) {
|
||||||
gotError = true;
|
gotError = true;
|
||||||
char szErrBuf[8096]="";
|
char szErrBuf[8096]="";
|
||||||
@@ -283,7 +297,7 @@ void World::init(Game *game, bool createUnits, bool initFactions){
|
|||||||
computeFow();
|
computeFow();
|
||||||
|
|
||||||
if(gotError == true) {
|
if(gotError == true) {
|
||||||
throw megaglest_runtime_error(sErrBuf);
|
throw megaglest_runtime_error(sErrBuf,!skipStackTrace);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -1622,7 +1636,7 @@ void World::placeUnitAtLocation(const Vec2i &location, int radius, Unit *unit, b
|
|||||||
char szBuf[4096]="";
|
char szBuf[4096]="";
|
||||||
sprintf(szBuf,"Unit: [%s] can't be placed, this error is caused because there\nis not enough room to put all units near their start location.\nmake a better/larger map. Faction: #%d name: [%s]",
|
sprintf(szBuf,"Unit: [%s] can't be placed, this error is caused because there\nis not enough room to put all units near their start location.\nmake a better/larger map. Faction: #%d name: [%s]",
|
||||||
unitName.c_str(),unitFactionIndex,unitFactionName.c_str());
|
unitName.c_str(),unitFactionIndex,unitFactionName.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,false);
|
||||||
}
|
}
|
||||||
if (unit->getType()->hasSkillClass(scBeBuilt)) {
|
if (unit->getType()->hasSkillClass(scBeBuilt)) {
|
||||||
map.flatternTerrain(unit);
|
map.flatternTerrain(unit);
|
||||||
@@ -1640,6 +1654,7 @@ void World::initUnits() {
|
|||||||
Logger::getInstance().add(Lang::getInstance().get("LogScreenGameLoadingGenerateGameElements","",true), true);
|
Logger::getInstance().add(Lang::getInstance().get("LogScreenGameLoadingGenerateGameElements","",true), true);
|
||||||
|
|
||||||
bool gotError = false;
|
bool gotError = false;
|
||||||
|
bool skipStackTrace = false;
|
||||||
string sErrBuf="";
|
string sErrBuf="";
|
||||||
try {
|
try {
|
||||||
//put starting units
|
//put starting units
|
||||||
@@ -1676,6 +1691,19 @@ void World::initUnits() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
gotError = true;
|
||||||
|
if(ex.wantStackTrace() == true) {
|
||||||
|
char szErrBuf[8096]="";
|
||||||
|
sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipStackTrace = true;
|
||||||
|
sErrBuf = ex.what();
|
||||||
|
}
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
|
||||||
|
}
|
||||||
catch(const std::exception &ex) {
|
catch(const std::exception &ex) {
|
||||||
gotError = true;
|
gotError = true;
|
||||||
char szErrBuf[8096]="";
|
char szErrBuf[8096]="";
|
||||||
@@ -1688,7 +1716,7 @@ void World::initUnits() {
|
|||||||
map.computeInterpolatedHeights();
|
map.computeInterpolatedHeights();
|
||||||
|
|
||||||
if(gotError == true) {
|
if(gotError == true) {
|
||||||
throw megaglest_runtime_error(sErrBuf);
|
throw megaglest_runtime_error(sErrBuf,!skipStackTrace);
|
||||||
}
|
}
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
@@ -29,8 +29,12 @@ using std::exception;
|
|||||||
namespace Shared { namespace Platform {
|
namespace Shared { namespace Platform {
|
||||||
|
|
||||||
class megaglest_runtime_error : public runtime_error {
|
class megaglest_runtime_error : public runtime_error {
|
||||||
|
protected:
|
||||||
|
bool noStackTrace;
|
||||||
public:
|
public:
|
||||||
megaglest_runtime_error(const string& __arg);
|
megaglest_runtime_error(const string& __arg,bool noStackTrace=false);
|
||||||
|
|
||||||
|
bool wantStackTrace() const { return noStackTrace; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
@@ -256,8 +256,8 @@ string PlatformExceptionHandler::getStackTrace() {
|
|||||||
return errMsg;
|
return errMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
megaglest_runtime_error::megaglest_runtime_error(const string& __arg)
|
megaglest_runtime_error::megaglest_runtime_error(const string& __arg,bool noStackTrace)
|
||||||
: std::runtime_error(__arg + PlatformExceptionHandler::getStackTrace()) {
|
: std::runtime_error(noStackTrace ? __arg + PlatformExceptionHandler::getStackTrace() : __arg), noStackTrace(noStackTrace) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -265,8 +265,8 @@ string PlatformExceptionHandler::getStackTrace() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
megaglest_runtime_error::megaglest_runtime_error(const string& __arg)
|
megaglest_runtime_error::megaglest_runtime_error(const string& __arg,bool noStackTrace)
|
||||||
: std::runtime_error(__arg + PlatformExceptionHandler::getStackTrace()) {
|
: std::runtime_error(noStackTrace ? __arg + PlatformExceptionHandler::getStackTrace() : __arg), noStackTrace(noStackTrace) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
Reference in New Issue
Block a user