Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5747


Ignore:
Timestamp:
Sep 19, 2009, 11:17:51 PM (15 years ago)
Author:
rgrieder
Message:

Added Exception::handleMessage() (copy from Game::getExceptionMessage) function that returns the exception message (if retrievable) when catching with "…"
and adjusted some exception handlers.

Location:
code/trunk/src
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/Orxonox.cc

    r5738 r5747  
    4545
    4646#include "util/Debug.h"
     47#include "util/Exception.h"
    4748#include "orxonox/Main.h"
    4849
     
    6768#endif
    6869    }
    69     catch (const std::exception& ex)
    70     {
    71         COUT(0) << "Orxonox failed to initialise: " << ex.what() << std::endl;
    72         COUT(0) << "Terminating program." << std::endl;
    73         return 1;
    74     }
    7570    catch (...)
    7671    {
    77         COUT(0) << "Orxonox failed to initialise: " << std::endl;
     72        COUT(0) << "Orxonox failed to initialise: " << orxonox::Exception::handleMessage() << std::endl;
    7873        COUT(0) << "Terminating program." << std::endl;
    7974        return 1;
  • code/trunk/src/libraries/core/Core.cc

    r5738 r5747  
    284284                            DynLibManager::getInstance().load(librarypath.string());
    285285                        }
    286                         catch (const std::exception& e)
    287                         {
    288                             COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << e.what() << std::endl;
    289                         }
    290286                        catch (...)
    291287                        {
    292                             COUT(1) << "Couldn't load module \"" << librarypath.string() << "\"" << std::endl;
     288                            COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << Exception::handleMessage() << std::endl;
    293289                        }
    294290                    }
     
    298294            }
    299295        }
    300         catch (const std::exception& e)
    301         {
    302             COUT(1) << "An error occurred while loading modules: " << e.what() << std::endl;
    303         }
    304296        catch (...)
    305297        {
    306             COUT(1) << "An error occurred while loading modules." << std::endl;
     298            COUT(1) << "An error occurred while loading modules: " << Exception::handleMessage() << std::endl;
    307299        }
    308300
     
    398390        catch (...)
    399391        {
    400             COUT(0) << "An exception occurred during 'new GraphicsManager' while "
    401                     << "another exception was being handled. This will lead to undefined behaviour!" << std::endl
     392            COUT(0) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << std::endl
     393                    << "Another exception might be being handled which may lead to undefined behaviour!" << std::endl
    402394                    << "Terminating the program." << std::endl;
    403395            abort();
  • code/trunk/src/libraries/core/Game.cc

    r5738 r5747  
    3737#include <exception>
    3838#include <boost/weak_ptr.hpp>
    39 #include <CEGUIExceptions.h>
    4039
    4140#include "util/Debug.h"
     
    204203            catch (...)
    205204            {
    206                 COUT(0) << "An exception occurred in the Core preUpdate: " << Game::getExceptionMessage() << std::endl;
     205                COUT(0) << "An exception occurred in the Core preUpdate: " << Exception::handleMessage() << std::endl;
    207206                COUT(0) << "This should really never happen! Closing the program." << std::endl;
    208207                this->stop();
     
    218217            catch (...)
    219218            {
    220             COUT(0) << "An exception occurred in the Core postUpdate: " << Game::getExceptionMessage() << std::endl;
    221             COUT(0) << "This should really never happen! Closing the program." << std::endl;
     219                COUT(0) << "An exception occurred in the Core postUpdate: " << Exception::handleMessage() << std::endl;
     220                COUT(0) << "This should really never happen! Closing the program." << std::endl;
    222221                this->stop();
    223222                break;
     
    254253                catch (...)
    255254                {
    256                     COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << Game::getExceptionMessage() << std::endl;
     255                    COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << Exception::handleMessage() << std::endl;
    257256                    // All scheduled operations have now been rendered inert --> flush them and issue a warning
    258257                    if (this->requestedStateNodes_.size() > 1)
     
    285284            catch (...)
    286285            {
    287                 COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << Game::getExceptionMessage() << std::endl;
     286                COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << Exception::handleMessage() << std::endl;
    288287                COUT(1) << "This should really never happen!" << std::endl;
    289288                COUT(1) << "Unloading all GameStates depending on the one that crashed." << std::endl;
     
    593592        catch (...)
    594593        {
    595             COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << Game::getExceptionMessage() << std::endl;
     594            COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << Exception::handleMessage() << std::endl;
    596595            COUT(2) << "         There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl;
    597596        }
     
    608607    }
    609608
    610     /*static*/ std::string Game::getExceptionMessage()
    611     {
    612         std::string exceptionMessage;
    613         try
    614         {
    615             // rethrow
    616             throw;
    617         }
    618         catch (const std::exception& ex)
    619         {
    620             return ex.what();
    621         }
    622         catch (const CEGUI::Exception& ex)
    623         {
    624 #if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6
    625             return GeneralException(ex.getMessage().c_str()).getDescription();
    626 #else
    627             return GeneralException(ex.getMessage().c_str(), ex.getLine(),
    628                 ex.getFileName().c_str(), ex.getName().c_str()).getDescription();
    629 #endif
    630         }
    631         catch (...)
    632         {
    633             return "Unknown exception";
    634         }
    635     }
    636 
    637609    std::map<std::string, shared_ptr<Game::GameStateFactory> > Game::GameStateFactory::factories_s;
    638610
  • code/trunk/src/libraries/core/Game.h

    r5738 r5747  
    155155        // ScopeGuard helper function
    156156        void resetChangingState() { this->bChangingState_ = false; }
    157         /**
    158         @brief
    159             Retrieves information from an exception caught with "..."
    160         @remarks
    161             Never ever call this function without an exception in the stack!
    162         */
    163         static std::string getExceptionMessage();
    164157
    165158        scoped_ptr<Clock>                  gameClock_;
  • code/trunk/src/libraries/core/GraphicsManager.cc

    r5738 r5747  
    172172        // scripts for the 1.6 version and then remove the inserted "particle_system"
    173173        // keyword. But we need to supply these new scripts as well, which is why
    174         // there is an extra Ogre::Archive dealing with in the memory.
     174        // there is an extra Ogre::Archive dealing with it in the memory.
    175175        using namespace Ogre;
    176176        ArchiveManager::getSingleton().addArchiveFactory(memoryArchiveFactory_.get());
  • code/trunk/src/libraries/core/IRC.cc

    r5738 r5747  
    3232
    3333#include "util/Convert.h"
     34#include "util/Exception.h"
    3435#include "ConsoleCommand.h"
    3536#include "CoreIncludes.h"
     
    6465        catch (Tcl::tcl_error const &e)
    6566        {   COUT(1) << "Tcl (IRC) error: " << e.what();   }
    66         catch (std::exception const &e)
    67         {   COUT(1) << "Error while initializing Tcl (IRC): " << e.what();   }
     67        catch (...)
     68        {   COUT(1) << "Error while initializing Tcl (IRC): " << Exception::handleMessage();   }
    6869
    6970        this->nickname_ = "orx" + multi_cast<std::string>(static_cast<unsigned int>(rand()));
     
    9495        catch (Tcl::tcl_error const &e)
    9596        {   COUT(1) << "Tcl (IRC) error: " << e.what();   }
    96         catch (std::exception const &e)
    97         {   COUT(1) << "Error while executing Tcl (IRC): " << e.what();   }
     97        catch (...)
     98        {   COUT(1) << "Error while executing Tcl (IRC): " << Exception::handleMessage();   }
    9899
    99100        return false;
  • code/trunk/src/libraries/core/Loader.cc

    r5738 r5747  
    187187            return false;
    188188        }
    189         catch (std::exception& ex)
     189        catch (...)
    190190        {
    191191            COUT(1) << std::endl;
    192192            COUT(1) << "An error occurred in Loader.cc while loading " << file->getFilename() << ":" << std::endl;
    193             COUT(1) << ex.what() << std::endl;
    194             COUT(1) << "Loading aborted." << std::endl;
    195             return false;
    196         }
    197         catch (...)
    198         {
    199             COUT(1) << std::endl;
    200             COUT(1) << "An unknown error occurred in Loader.cc while loading " << file->getFilename() << ":" << std::endl;
     193            COUT(1) << Exception::handleMessage() << std::endl;
    201194            COUT(1) << "Loading aborted." << std::endl;
    202195            return false;
  • code/trunk/src/libraries/core/TclBind.cc

    r5738 r5747  
    3535#include "SpecialConfig.h"
    3636#include "util/Debug.h"
     37#include "util/Exception.h"
    3738#include "util/StringUtils.h"
    3839#include "CommandExecutor.h"
     
    9293            catch (Tcl::tcl_error const &e)
    9394            {   COUT(1) << "Tcl error while creating Tcl-interpreter: " << e.what() << std::endl;   }
    94             catch (std::exception const &e)
    95             {   COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl;   }
    9695            catch (...)
    97             {   COUT(1) << "Error while creating Tcl-interpreter." << std::endl;   }
     96            {   COUT(1) << "Error while creating Tcl-interpreter: " << Exception::handleMessage() << std::endl;   }
    9897        }
    9998    }
     
    115114        catch (Tcl::tcl_error const &e)
    116115        {   COUT(1) << "Tcl error while creating Tcl-interpreter: " << e.what() << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl;   }
    117         catch (std::exception const &e)
    118         {   COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl;   }
    119116        catch (...)
    120         {   COUT(1) << "Error while creating Tcl-interpreter." << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl;   }
     117        {   COUT(1) << "Error while creating Tcl-interpreter: " << Exception::handleMessage() << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl;   }
    121118
    122119        return interpreter;
     
    178175            catch (Tcl::tcl_error const &e)
    179176            {   COUT(1) << "tcl> Error: " << e.what() << std::endl;   }
    180             catch (std::exception const &e)
    181             {   COUT(1) << "Error while executing Tcl: " << e.what() << std::endl;   }
     177            catch (...)
     178            {   COUT(1) << "Error while executing Tcl: " << Exception::handleMessage() << std::endl;   }
    182179        }
    183180
     
    199196        catch (Tcl::tcl_error const &e)
    200197        {   COUT(1) << "Tcl error: " << e.what() << std::endl;   }
    201         catch (std::exception const &e)
    202         {   COUT(1) << "Error while executing Tcl: " << e.what() << std::endl;   }
     198        catch (...)
     199        {   COUT(1) << "Error while executing Tcl: " << Exception::handleMessage() << std::endl;   }
    203200
    204201        return false;
  • code/trunk/src/libraries/core/TclThreadManager.cc

    r5738 r5747  
    3737
    3838#include "util/Convert.h"
     39#include "util/Exception.h"
    3940#include "Clock.h"
    4041#include "CommandExecutor.h"
     
    285286        catch (const Tcl::tcl_error& e)
    286287        {   bundle->interpreter_ = 0; COUT(1) << "Tcl error while creating Tcl-interpreter (" << id_string << "): " << e.what() << std::endl;   }
    287         catch (const std::exception& e)
    288         {   bundle->interpreter_ = 0; COUT(1) << "Error while creating Tcl-interpreter (" << id_string << "): " << e.what() << std::endl;   }
    289288        catch (...)
    290         {   bundle->interpreter_ = 0; COUT(1) << "An error occurred while creating a new Tcl-interpreter (" << id_string << ")" << std::endl;   }
     289        {   bundle->interpreter_ = 0; COUT(1) << "Error while creating Tcl-interpreter (" << id_string << "): " << Exception::handleMessage() << std::endl;   }
    291290    }
    292291
  • code/trunk/src/libraries/core/XMLPort.h

    r5738 r5747  
    591591                                                    throw ex;
    592592                                                }
    593                                                 catch (std::exception& ex)
     593                                                catch (...)
    594594                                                {
    595595                                                    COUT(1) << "An error occurred while loading object:" << std::endl;
    596                                                     COUT(1) << ex.what() << std::endl;
    597                                                 }
    598                                                 catch (...)
    599                                                 {
    600                                                     COUT(1) << "An unknown error occurred while loading object." << std::endl;
     596                                                    COUT(1) << Exception::handleMessage() << std::endl;
    601597                                                }
    602598                                            }
  • code/trunk/src/libraries/core/input/InputDevice.h

    r5738 r5747  
    4242
    4343#include "util/Debug.h"
     44#include "util/Exception.h"
    4445#include "core/Clock.h"
    4546#include "InputState.h"
     
    145146            catch (...)
    146147            {
    147                 COUT(1) << this->getClassName() << " destruction failed! Potential resource leak!" << std::endl;
     148                COUT(1) << this->getClassName() << " destruction failed: " << Exception::handleMessage() << std::endl
     149                        << "    Potential resource leak!" << std::endl;
    148150            }
    149151        }
  • code/trunk/src/libraries/core/input/InputManager.cc

    r5738 r5747  
    330330            catch (...)
    331331            {
    332                 CCOUT(1) << className << " destruction failed! Potential resource leak!" << std::endl;
     332                COUT(1) << className << " destruction failed: " << Exception::handleMessage() << std::endl
     333                        << "    Potential resource leak!" << std::endl;
    333334            }
    334335        }
     
    342343        catch (...)
    343344        {
    344             CCOUT(1) << "OIS::InputManager destruction failed! Potential resource leak!" << std::endl;
     345            COUT(1) << "OIS::InputManager destruction failed" << Exception::handleMessage() << std::endl
     346                    << "    Potential resource leak!" << std::endl;
    345347        }
    346348        oisInputManager_ = NULL;
  • code/trunk/src/libraries/tools/ResourceLocation.cc

    r5738 r5747  
    9797                this->getPath(), this->getResourceGroup());
    9898        }
    99         catch (const std::exception& ex)
     99        catch (...)
    100100        {
    101             COUT(1) << "Removing of a ResourceLocation failed: " << ex.what() << std::endl;
     101            COUT(1) << "Removing of a ResourceLocation failed: " << Exception::handleMessage() << std::endl;
    102102        }
    103103    }
  • code/trunk/src/libraries/util/CMakeLists.txt

    r5738 r5747  
    7474    "UTIL_SHARED_BUILD"
    7575  LINK_LIBRARIES
     76    ${CEGUI_LIBRARY}
    7677    ${OGRE_LIBRARY}
    7778  SOURCE_FILES
  • code/trunk/src/libraries/util/Exception.cc

    r5738 r5747  
    3434
    3535#include "Exception.h"
     36#include <CEGUIExceptions.h>
    3637
    3738namespace orxonox
     
    9394        return getDescription().c_str();
    9495    }
     96
     97    /*static*/ std::string Exception::handleMessage()
     98    {
     99        try
     100        {
     101            // rethrow
     102            throw;
     103        }
     104        catch (const std::exception& ex)
     105        {
     106            return ex.what();
     107        }
     108        catch (const CEGUI::Exception& ex)
     109        {
     110#if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6
     111            return GeneralException(ex.getMessage().c_str()).getDescription();
     112#else
     113            return GeneralException(ex.getMessage().c_str(), ex.getLine(),
     114                ex.getFileName().c_str(), ex.getName().c_str()).getDescription();
     115#endif
     116        }
     117        catch (...)
     118        {
     119            return "Unknown exception";
     120        }
     121    }
    95122}
  • code/trunk/src/libraries/util/Exception.h

    r5738 r5747  
    8383        virtual const std::string& getFilename()        const { return this->filename_; }
    8484
     85        /**
     86        @brief
     87            Retrieves information from an exception caught with "..."
     88            Works for std::exception and CEGUI::Exception
     89        @remarks
     90            Never ever call this function without an exception in the stack!
     91        */
     92        static std::string handleMessage();
     93
    8594    protected:
    8695        std::string description_;             //!< User typed text about why the exception occurred
  • code/trunk/src/orxonox/graphics/ParticleEmitter.cc

    r5738 r5747  
    110110            {
    111111                this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), this->source_, this->LOD_);
    112                 this->attachOgreObject(this->particles_->getParticleSystem());
    113                 this->particles_->setVisible(this->isVisible());
    114                 this->particles_->setEnabled(this->isActive());
    115112            }
    116113            catch (...)
    117114            {
    118                 COUT(1) << "Error: Couln't load particle effect \"" << this->source_ << "\"" << std::endl;
    119                 this->particles_ = 0;
     115                COUT(1) << "Error: Couln't load particle effect \"" << this->source_ << "\" because:" << std::endl
     116                        << Exception::handleMessage() << std::endl;
    120117            }
     118            this->attachOgreObject(this->particles_->getParticleSystem());
     119            this->particles_->setVisible(this->isVisible());
     120            this->particles_->setEnabled(this->isActive());
    121121        }
    122122    }
  • code/trunk/src/orxonox/worldentities/BigExplosion.cc

    r5738 r5747  
    7474            catch (...)
    7575            {
    76                 COUT(1) << "Error: Couln't load particle effect in BigExplosion." << std::endl;
     76                COUT(1) << "Error: Couln't load particle effect in BigExplosion: " << Exception::handleMessage() << std::endl;
    7777                this->initZero();
    7878            }
     
    9797    void BigExplosion::init()
    9898    {
    99         Identifier* idDE1 = Class(MovableEntity);
    100         BaseObject* oDE1 = idDE1->fabricate(this);
    101         this->debrisEntity1_ = orxonox_cast<MovableEntity*>(oDE1);
    102 
    103         Identifier* idDE2 = Class(MovableEntity);
    104         BaseObject* oDE2 = idDE2->fabricate(this);
    105         this->debrisEntity2_ = orxonox_cast<MovableEntity*>(oDE2);
    106 
    107         Identifier* idDE3 = Class(MovableEntity);
    108         BaseObject* oDE3 = idDE3 ->fabricate(this);
    109         this->debrisEntity3_ = orxonox_cast<MovableEntity*>(oDE3);
    110 
    111         Identifier* idDE4 = Class(MovableEntity);
    112         BaseObject* oDE4 = idDE4->fabricate(this);
    113         this->debrisEntity4_ = orxonox_cast<MovableEntity*>(oDE4);
    114 
    115         Identifier* idD1 = Class(Model);
    116         BaseObject* oD1 = idD1->fabricate(this);
    117         this->debris1_ = orxonox_cast<Model*>(oD1);
    118 
    119         Identifier* idD2 = Class(Model);
    120         BaseObject* oD2 = idD2->fabricate(this);
    121         this->debris2_ = orxonox_cast<Model*>(oD2);
    122 
    123         Identifier* idD3 = Class(Model);
    124         BaseObject* oD3 = idD3->fabricate(this);
    125         this->debris3_ = orxonox_cast<Model*>(oD3);
    126 
    127         Identifier* idD4 = Class(Model);
    128         BaseObject* oD4 = idD4->fabricate(this);
    129         this->debris4_ = orxonox_cast<Model*>(oD4);
    130 
    131         Identifier* id6 = Class(StaticEntity);
    132         BaseObject* object4 = id6->fabricate(this);
    133         this->explosion_ = orxonox_cast<StaticEntity*>(object4);
     99        this->debrisEntity1_ = new MovableEntity(this);
     100        this->debrisEntity2_ = new MovableEntity(this);
     101        this->debrisEntity3_ = new MovableEntity(this);
     102        this->debrisEntity4_ = new MovableEntity(this);
     103
     104        this->debris1_ = new Model(this);
     105        this->debris2_ = new Model(this);
     106        this->debris3_ = new Model(this);
     107        this->debris4_ = new Model(this);
     108
     109        this->explosion_ = new StaticEntity(this);
    134110
    135111        this->debrisSmoke1_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
     
    200176        for(int i=0;i<10;i++)
    201177        {
    202             Identifier* idf1 = Class(Model);
    203             BaseObject* obj1 = idf1->fabricate(this);
    204             Model* part1 = orxonox_cast<Model*>(obj1);
    205 
    206 
    207             Identifier* idf2 = Class(Model);
    208             BaseObject* obj2 = idf2->fabricate(this);
    209             Model* part2 = orxonox_cast<Model*>(obj2);
    210 
    211             Identifier* idf3 = Class(MovableEntity);
    212             BaseObject* obj3 = idf3->fabricate(this);
    213             MovableEntity* partEntity1 = orxonox_cast<MovableEntity*>(obj3);
    214 
    215             Identifier* idf4 = Class(MovableEntity);
    216             BaseObject* obj4 = idf4->fabricate(this);
    217             MovableEntity* partEntity2 = orxonox_cast<MovableEntity*>(obj4);
     178            Model* part1 = new Model(this);
     179            Model* part2 = new Model(this);
     180
     181            MovableEntity* partEntity1 = new MovableEntity(this);
     182            MovableEntity* partEntity2 = new MovableEntity(this);
    218183
    219184            partEntity1->setVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1))*rnd(10,100));
     
    227192            part1->setMeshSource("SmallPart1.mesh");
    228193            part2->setMeshSource("SmallPart2.mesh");
    229 
    230194
    231195            partEntity1->attach(part1);
  • code/trunk/src/orxonox/worldentities/ExplosionChunk.cc

    r5738 r5747  
    6161            catch (...)
    6262            {
    63                 COUT(1) << "Error: Couln't load particle effect in ExplosionChunk." << std::endl;
     63                COUT(1) << "Error: Couln't load particle effect in ExplosionChunk: " << Exception::handleMessage() << std::endl;
    6464                this->fire_ = 0;
    6565                this->smoke_ = 0;
Note: See TracChangeset for help on using the changeset viewer.