From 8357eeb762562409ad9def66e6afa8e1d922bc2c Mon Sep 17 00:00:00 2001 From: ehofman Date: Sun, 11 Dec 2005 13:35:05 +0000 Subject: [PATCH] Vassilii Khachaturov: * in some cases more specific sg exception types were used in place of the more generic one, e.g., sg_io_exception instead of sg_exception when the context of the error was an IO error * in some cases, the error message was made more specific * minor style fix for exception rethrowing --- using throw; whenever a re-throw is made; sometimes optimizing away the exception symbol name in the catch handler at all * more specific catch handlers added in some places -- e.g., an sg_io_exception caught ahead of sg_exception --- simgear/environment/metar.cxx | 9 +++++---- simgear/scene/material/matlib.cxx | 2 +- simgear/scene/model/model.cxx | 3 ++- simgear/sound/sample_openal.cxx | 9 ++++++--- simgear/xml/easyxml.cxx | 8 ++++---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/simgear/environment/metar.cxx b/simgear/environment/metar.cxx index fa7477f5..1c191963 100644 --- a/simgear/environment/metar.cxx +++ b/simgear/environment/metar.cxx @@ -107,7 +107,7 @@ SGMetar::SGMetar(const string& m, const string& proxy, const string& port, scanType(); if (!scanId() || !scanDate()) { delete[] _data; - throw sg_io_exception("metar data bogus (" + _url + ')'); + throw sg_io_exception("metar data bogus ", sg_location(_url)); } scanModifier(); @@ -133,7 +133,7 @@ SGMetar::SGMetar(const string& m, const string& proxy, const string& port, if (_grpcount < 4) { delete[] _data; - throw sg_io_exception("metar data incomplete (" + _url + ')'); + throw sg_io_exception("metar data incomplete ", sg_location(_url)); } _url = ""; @@ -196,7 +196,7 @@ char *SGMetar::loadData(const char *id, const string& proxy, const string& port, sock->set_timeout(10000); if (!sock->open(SG_IO_OUT)) { delete sock; - throw sg_io_exception("cannot connect to " + host); + throw sg_io_exception("cannot connect to ", sg_location(host)); } string get = "GET "; @@ -233,7 +233,8 @@ char *SGMetar::loadData(const char *id, const string& proxy, const string& port, char *b = buf; scanBoundary(&b); if (*b == '<') - throw sg_io_exception("no metar data available from " + _url); + throw sg_io_exception("no metar data available from ", + sg_location(_url)); char *metar = new char[strlen(b) + 2]; // make room for " \0" strcpy(metar, b); diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index 5ce238b5..7264022d 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -185,7 +185,7 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char } catch (const sg_exception &ex) { SG_LOG( SG_INPUT, SG_ALERT, "Error reading materials: " << ex.getMessage() ); - throw ex; + throw; } int nMaterials = materials.nChildren(); diff --git a/simgear/scene/model/model.cxx b/simgear/scene/model/model.cxx index c44509db..48adc59f 100644 --- a/simgear/scene/model/model.cxx +++ b/simgear/scene/model/model.cxx @@ -283,7 +283,8 @@ sgLoad3DModel( const string &fg_root, const string &path, ssgTexturePath((char *)texturepath.c_str()); model = (ssgBranch *)ssgLoad((char *)modelpath.c_str()); if (model == 0) - throw sg_exception("Failed to load 3D model"); + throw sg_io_exception("Failed to load 3D model", + sg_location(modelpath.str())); } // Set up the alignment node ssgTransform * alignmainmodel = new ssgTransform; diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 6f913bd8..d07970a3 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -118,7 +118,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file) : if (buffer == AL_NONE) { ALenum error = alutGetError (); print_openal_error("constructor (alutCreateBufferFromFile)"); - throw sg_exception("Failed to load wav file: "+string(alutGetErrorString (error))); + throw sg_io_exception("Failed to load wav file: ", + sg_location(string(alutGetErrorString (error)))); } #else @@ -383,7 +384,8 @@ SGSoundSample::load_file(const char *path, const char *file) ALfloat freqf; data = alutLoadMemoryFromFile(samplepath.c_str(), &format, &size, &freqf ); if (data == NULL) { - throw sg_exception("Failed to load wav file."); + throw sg_io_exception("Failed to load wav file.", + sg_location(samplepath.str())); } freq = (ALsizei)freqf; #else @@ -395,7 +397,8 @@ SGSoundSample::load_file(const char *path, const char *file) &format, &data, &size, &freq, &loop ); # endif if ( print_openal_error("constructor (alutLoadWAVFile)") ) { - throw sg_exception("Failed to load wav file."); + throw sg_io_exception("Failed to load wav file.", + sg_location(samplepath.str())); } #endif diff --git a/simgear/xml/easyxml.cxx b/simgear/xml/easyxml.cxx index dbebf0ca..57a1bee2 100644 --- a/simgear/xml/easyxml.cxx +++ b/simgear/xml/easyxml.cxx @@ -263,12 +263,12 @@ readXML (const string &path, XMLVisitor &visitor) if (input.good()) { try { readXML(input, visitor, path); - } catch (sg_io_exception &e) { + } catch (sg_io_exception &) { input.close(); - throw e; - } catch (sg_throwable &t) { + throw; + } catch (sg_throwable &) { input.close(); - throw t; + throw; } } else { throw sg_io_exception("Failed to open file", sg_location(path), -- 2.39.5