Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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/libraries
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.