pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] [pingus] push by address@hidden - Replaced "throw std::runt


From: pingus
Subject: [Pingus-CVS] [pingus] push by address@hidden - Replaced "throw std::runtime_error" with "raise_exception(std::runtime... on 2011-11-28 13:44 GMT
Date: Mon, 28 Nov 2011 13:46:01 +0000

Revision: 2f7a648b6945
Author:   Ingo Ruhnke <address@hidden>
Date:     Mon Nov 28 05:44:37 2011
Log: Replaced "throw std::runtime_error" with "raise_exception(std::runtime_error, "

http://code.google.com/p/pingus/source/detail?r=2f7a648b6945

Modified:
 /src/editor/generic_level_obj.cpp
 /src/engine/display/display.cpp
 /src/engine/display/font_description.cpp
 /src/engine/input/controller_description.cpp
 /src/engine/input/manager.cpp
 /src/engine/sound/sound_real.cpp
 /src/pingus/ground_map.cpp
 /src/pingus/levelset.cpp
 /src/pingus/pingus_demo.cpp
 /src/pingus/pingus_level.cpp
 /src/pingus/prefab_file.cpp
 /src/pingus/server_event.cpp
 /src/pingus/state_sprite.cpp
 /src/pingus/worldmap/dot_factory.cpp
 /src/pingus/worldmap/path_graph.cpp
 /src/pingus/worldmap/pingus_worldmap.cpp
 /src/pingus/worldmap/worldmap_story.cpp
 /src/util/command_line_generic.cpp
 /src/util/system.cpp

=======================================
--- /src/editor/generic_level_obj.cpp   Mon Oct 17 14:44:35 2011
+++ /src/editor/generic_level_obj.cpp   Mon Nov 28 05:44:37 2011
@@ -21,6 +21,7 @@
 #include "engine/display/drawing_context.hpp"
 #include "pingus/resource.hpp"
 #include "util/log.hpp"
+#include "util/raise_exception.hpp"

 namespace Editor {

@@ -144,9 +145,7 @@
     return HAS_SPRITE_FAKE | HAS_TARGET_ID;
   else
   {
-    std::ostringstream out;
-    out << "unknown object type: '" << obj_type << "'";
-    throw std::runtime_error(out.str());
+ raise_exception(std::runtime_error, "unknown object type: '" << obj_type << "'");
   }
 }

=======================================
--- /src/engine/display/display.cpp     Sat Oct 22 11:10:17 2011
+++ /src/engine/display/display.cpp     Mon Nov 28 05:44:37 2011
@@ -99,7 +99,7 @@
s_framebuffer = std::unique_ptr<Framebuffer>(new OpenGLFramebuffer());
       s_framebuffer->set_video_mode(size, fullscreen, resizable);
 #else
-      throw std::runtime_error("OpenGL support was not compiled in");
+ raise_exception(std::runtime_error, "OpenGL support was not compiled in");
 #endif
       break;

=======================================
--- /src/engine/display/font_description.cpp    Wed Sep 21 08:08:26 2011
+++ /src/engine/display/font_description.cpp    Mon Nov 28 05:44:37 2011
@@ -19,6 +19,7 @@
 #include <stdexcept>

 #include "util/file_reader.hpp"
+#include "util/raise_exception.hpp"

 GlyphDescription::GlyphDescription() :
   image(0),
@@ -58,7 +59,7 @@

   if (reader.get_name() != "pingus-font")
   {
-    throw std::runtime_error("FontDescription: not a pingus-font file");
+ raise_exception(std::runtime_error, "FontDescription: not a pingus-font file");
   }
   else
   {
=======================================
--- /src/engine/input/controller_description.cpp        Fri Nov  6 20:23:49 2009
+++ /src/engine/input/controller_description.cpp        Mon Nov 28 05:44:37 2011
@@ -18,6 +18,8 @@

 #include <stdexcept>

+#include "util/raise_exception.hpp"
+
 namespace Input {

 ControllerDescription::ControllerDescription() :
@@ -100,8 +102,9 @@
 {
std::map<int, InputEventDefinition>::const_iterator i = id_to_event.find(id);
   if (i == id_to_event.end())
-    throw std::runtime_error("Unknown event id");
-
+  {
+    raise_exception(std::runtime_error, "Unknown event id");
+  }
   return i->second;
 }

@@ -110,7 +113,7 @@
 {
std::map<std::string, InputEventDefinition>::const_iterator i = str_to_event.find(name);
   if (i == str_to_event.end())
-    throw std::runtime_error("Unknown event str: " + name);
+    raise_exception(std::runtime_error, "Unknown event str: " << name);

   return i->second;
 }
=======================================
--- /src/engine/input/manager.cpp       Tue Sep 20 15:44:32 2011
+++ /src/engine/input/manager.cpp       Mon Nov 28 05:44:37 2011
@@ -21,6 +21,7 @@
 #include "engine/input/driver_factory.hpp"
 #include "util/log.hpp"
 #include "util/pathname.hpp"
+#include "util/raise_exception.hpp"
 #include "util/string_util.hpp"

 namespace Input {
@@ -90,7 +91,8 @@

   if (reader.get_name() != "pingus-controller")
   {
- throw std::runtime_error("Controller: invalid config file '" + filename.str() + "'");
+    raise_exception(std::runtime_error,
+ "Controller: invalid config file '" << filename.str() << "'");
   }
   else
   {
@@ -172,8 +174,8 @@
       }
       else
       {
- throw std::runtime_error(std::string("Manager: Unkown Element in Controller Config: ")
-                                 + i->get_name());
+ raise_exception(std::runtime_error, "Manager: Unkown Element in Controller Config: "
+                        << i->get_name());
       }
     }
   }
=======================================
--- /src/engine/sound/sound_real.cpp    Mon Oct  3 09:37:32 2011
+++ /src/engine/sound/sound_real.cpp    Mon Nov 28 05:44:37 2011
@@ -22,6 +22,7 @@
 #include "engine/sound/sound_res_mgr.hpp"
 #include "pingus/globals.hpp"
 #include "util/log.hpp"
+#include "util/raise_exception.hpp"

 namespace Sound {

@@ -35,16 +36,14 @@

   if (SDL_Init(SDL_INIT_AUDIO) == -1)
   {
-    log_error("Unable to initialize SDL: " << SDL_GetError());
-    throw std::runtime_error(SDL_GetError());
+ raise_exception(std::runtime_error, "Unable to initialize SDL: " << SDL_GetError());
   }

   log_info("Initializing SDL_Mixer");

   if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) == -1)
   {
-    log_error("Unable to initialize SDL_Mixer: " << Mix_GetError());
-    throw std::runtime_error(Mix_GetError());
+ raise_exception(std::runtime_error, "Unable to initialize SDL_Mixer: " << Mix_GetError());
   }
 }

=======================================
--- /src/pingus/ground_map.cpp  Wed Sep 28 08:15:30 2011
+++ /src/pingus/ground_map.cpp  Mon Nov 28 05:44:37 2011
@@ -20,6 +20,7 @@

 #include "engine/display/scene_context.hpp"
 #include "pingus/collision_map.hpp"
+#include "util/raise_exception.hpp"

 class MapTile
 {
@@ -202,8 +203,9 @@
 {
   if (sprovider.get_surface()->format->BitsPerPixel != 8)
   {
- throw std::runtime_error(std::string("SpotMap::put_alpha_surface: Image has wrong color depth: " - + sprovider.get_surface()->format->BitsPerPixel));
+    raise_exception(std::runtime_error,
+ "SpotMap::put_alpha_surface: Image has wrong color depth: "
+                    << sprovider.get_surface()->format->BitsPerPixel);
   }

   int swidth  = sprovider.get_width();
=======================================
--- /src/pingus/levelset.cpp    Thu Oct 20 10:31:54 2011
+++ /src/pingus/levelset.cpp    Mon Nov 28 05:44:37 2011
@@ -61,7 +61,7 @@
   FileReader reader = FileReader::parse(pathname);
   if (reader.get_name() != "pingus-levelset")
   {
- throw std::runtime_error("Error: " + pathname.str() + ": not a 'pingus-levelset' file"); + raise_exception(std::runtime_error, "Error: " << pathname.str() << ": not a 'pingus-levelset' file");
   }
   else
   {
=======================================
--- /src/pingus/pingus_demo.cpp Wed Sep 21 08:08:26 2011
+++ /src/pingus/pingus_demo.cpp Mon Nov 28 05:44:37 2011
@@ -21,6 +21,7 @@
 #include "util/file_reader.hpp"
 #include "util/pathname.hpp"
 #include "util/log.hpp"
+#include "util/raise_exception.hpp"

 PingusDemo::PingusDemo(const Pathname& pathname) :
   m_levelname(),
@@ -31,7 +32,7 @@

   if (lines.empty())
   {
- throw std::runtime_error("'" + pathname.str() + "', demo file is empty"); + raise_exception(std::runtime_error, "'" << pathname.str() << "', demo file is empty");
   }
   else
   {
@@ -40,7 +41,7 @@
       const FileReader& reader = lines.front();
       if (!reader.read_string("name", m_levelname))
       {
- throw std::runtime_error("(level (name ...)) entry missing in demo file '" + pathname.str() + "'"); + raise_exception(std::runtime_error, "(level (name ...)) entry missing in demo file '" << pathname.str() << "'");
       }

       reader.read_string("checksum", m_checksum);
=======================================
--- /src/pingus/pingus_level.cpp        Tue Oct 11 07:55:43 2011
+++ /src/pingus/pingus_level.cpp        Mon Nov 28 05:44:37 2011
@@ -22,6 +22,7 @@
 #include "pingus/pingus_level_impl.hpp"
 #include "util/log.hpp"
 #include "util/pathname.hpp"
+#include "util/raise_exception.hpp"
 #include "util/system.hpp"

 PingusLevel::PingusLevel() :
@@ -58,7 +59,7 @@

   if (reader.get_name() != "pingus-level")
   {
- throw std::runtime_error("Error: " + pathname.str() + ": not a 'pingus-level' file"); + raise_exception(std::runtime_error, "Error: " << pathname.str() << ": not a 'pingus-level' file");
   }
   else
   {
@@ -71,7 +72,7 @@
     FileReader head;
     if (!reader.read_section("head", head))
     {
- throw std::runtime_error("Error: (head) section not found in '" + pathname.str() + "'"); + raise_exception(std::runtime_error, "Error: (head) section not found in '" << pathname.str() << "'");
     }
     else
     {
@@ -102,7 +103,8 @@
       }
       else
       {
- throw std::runtime_error("Error: (pingus-level head actions) not found in '" + pathname.str() + "'");
+        raise_exception(std::runtime_error,
+ "Error: (pingus-level head actions) not found in '" << pathname.str() << "'");
       }
     }

=======================================
--- /src/pingus/prefab_file.cpp Thu Sep 15 03:57:04 2011
+++ /src/pingus/prefab_file.cpp Mon Nov 28 05:44:37 2011
@@ -20,6 +20,7 @@

 #include "util/file_reader.hpp"
 #include "util/log.hpp"
+#include "util/raise_exception.hpp"
 #include "util/system.hpp"

 PrefabFile
@@ -29,7 +30,7 @@

   if (reader.get_name() != "pingus-prefab")
   {
- throw std::runtime_error("Error: " + filename.str() + ": not a 'pingus-prefab' file"); + raise_exception(std::runtime_error, "Error: " << filename.str() << ": not a 'pingus-prefab' file");
   }
   else
   {
@@ -39,7 +40,7 @@
     FileReader objects;
if (!reader.read_section("objects", objects) || objects.get_sections().empty())
     {
- throw std::runtime_error("Error: " + filename.str() + ": empty prefab file"); + raise_exception(std::runtime_error, "Error: " << filename.str() << ": empty prefab file");
     }
     else
     {
=======================================
--- /src/pingus/server_event.cpp        Mon Sep  5 14:46:01 2011
+++ /src/pingus/server_event.cpp        Mon Nov 28 05:44:37 2011
@@ -22,6 +22,7 @@
 #include "pingus/world.hpp"
 #include "util/file_reader.hpp"
 #include "util/log.hpp"
+#include "util/raise_exception.hpp"

 ServerEvent::ServerEvent() :
   type(PINGU_ACTION_EVENT),
@@ -75,8 +76,7 @@
   }
   else
   {
- throw std::runtime_error(std::string("ServerEvent: Parse error: Unknown event: ")
-                             + reader.get_name());
+ raise_exception(std::runtime_error, "ServerEvent: Parse error: Unknown event: " << reader.get_name());
   }
 }

=======================================
--- /src/pingus/state_sprite.cpp        Tue Sep  6 07:55:24 2011
+++ /src/pingus/state_sprite.cpp        Mon Nov 28 05:44:37 2011
@@ -19,6 +19,8 @@
 #include <sstream>
 #include <stdexcept>

+#include "util/raise_exception.hpp"
+
 StateSprite::StateSprite() :
   sprites()
 {
@@ -59,9 +61,7 @@
   }
   else
   {
-    std::ostringstream out;
-    out << "StateSprite error: state " << state << " not available";
-    throw std::runtime_error(out.str());
+ raise_exception(std::runtime_error, "StateSprite error: state " << state << " not available");
   }
 }

=======================================
--- /src/pingus/worldmap/dot_factory.cpp        Sun Oct  2 10:52:25 2011
+++ /src/pingus/worldmap/dot_factory.cpp        Mon Nov 28 05:44:37 2011
@@ -20,6 +20,7 @@

 #include "pingus/worldmap/level_dot.hpp"
 #include "pingus/worldmap/story_dot.hpp"
+#include "util/raise_exception.hpp"

 namespace WorldmapNS {

@@ -34,11 +35,11 @@
   {
     return new LevelDot(reader);
   }
-  else if (reader.get_name() == "tubedot")
-  {
-    throw std::runtime_error("DotFactory: unknown tag: ");
-  }
-  return 0;
+  else
+  {
+ raise_exception(std::runtime_error, "DotFactory: unknown tag: " << reader.get_name());
+    return 0;
+  }
 }

 } // namespace WorldmapNS
=======================================
--- /src/pingus/worldmap/path_graph.cpp Wed Sep 28 09:41:01 2011
+++ /src/pingus/worldmap/path_graph.cpp Mon Nov 28 05:44:37 2011
@@ -22,6 +22,7 @@
 #include "pingus/worldmap/path_drawable.hpp"
 #include "pingus/worldmap/worldmap.hpp"
 #include "util/log.hpp"
+#include "util/raise_exception.hpp"

 namespace WorldmapNS {

@@ -150,7 +151,7 @@
     }
     else
     {
-      throw std::runtime_error("PathGraph: unhandled: ");
+      raise_exception(std::runtime_error, "PathGraph: unhandled: ");
     }
   }
 }
=======================================
--- /src/pingus/worldmap/pingus_worldmap.cpp    Fri Sep 30 09:16:45 2011
+++ /src/pingus/worldmap/pingus_worldmap.cpp    Mon Nov 28 05:44:37 2011
@@ -19,6 +19,7 @@
 #include <stdexcept>

 #include "util/pathname.hpp"
+#include "util/raise_exception.hpp"

 using namespace WorldmapNS;

@@ -82,7 +83,7 @@
   {
     if (!reader.read_section("graph", impl->path_graph))
     {
- throw std::runtime_error("Worldmap: " + impl->filename + " is missed 'graph' section"); + raise_exception(std::runtime_error, "Worldmap: " << impl->filename << " is missed 'graph' section");
     }

     impl->objects = reader.read_section("objects").get_sections();
@@ -104,7 +105,7 @@
   }
   else
   {
- throw std::runtime_error("Worldmap:" + impl->filename + ": not a Worldmap file"); + raise_exception(std::runtime_error, "Worldmap:" << impl->filename << ": not a Worldmap file");
   }
 }

=======================================
--- /src/pingus/worldmap/worldmap_story.cpp     Wed Sep 21 08:08:26 2011
+++ /src/pingus/worldmap/worldmap_story.cpp     Mon Nov 28 05:44:37 2011
@@ -23,6 +23,7 @@
 #include "pingus/gettext.h"
 #include "pingus/string_format.hpp"
 #include "util/file_reader.hpp"
+#include "util/raise_exception.hpp"

 namespace WorldmapNS {

@@ -56,7 +57,7 @@
   std::reverse(pages.begin(), pages.end());

   if (pages.empty())
- throw std::runtime_error("WorldmapStory: Worldmap does not include a valid story"); + raise_exception(std::runtime_error, "WorldmapStory: Worldmap does not include a valid story");
 }

 } // namespace WorldmapNS
=======================================
--- /src/util/command_line_generic.cpp  Fri Nov  6 12:37:52 2009
+++ /src/util/command_line_generic.cpp  Mon Nov 28 05:44:37 2011
@@ -34,6 +34,8 @@
 #include <stdexcept>
 #include <stdio.h>

+#include "util/raise_exception.hpp"
+
 #ifdef WIN32
 #define snprintf _snprintf
 #endif
@@ -104,7 +106,8 @@
               {
                 if (i == argc - 1)
                 {
- throw std::runtime_error("option '" + std::string(argv[i]) + "' requires an argument");
+                  raise_exception(std::runtime_error,
+ "option '" << std::string(argv[i]) << "' requires an argument");
                 }
                 else
                 {
@@ -116,7 +119,7 @@
           }
           else
           {
- throw std::runtime_error("unrecognized option '" + std::string(argv[i]) + "'"); + raise_exception(std::runtime_error, "unrecognized option '" << std::string(argv[i]) << "'");
           }
         }
       }
@@ -143,7 +146,7 @@
                 if (i == argc - 1 || *(p+1) != '\0')
                 {
                   // No more arguments
- throw std::runtime_error("option requires an argument -- " + std::string(1, *p)); + raise_exception(std::runtime_error, "option requires an argument -- " << std::string(1, *p));
                 }
                 else
                 {
@@ -154,7 +157,7 @@
             }
             else
             {
- throw std::runtime_error("invalid option -- " + std::string(1, *p)); + raise_exception(std::runtime_error, "invalid option -- " << std::string(1, *p));
             }
             ++p;
           }
=======================================
--- /src/util/system.cpp        Fri Oct 14 09:49:39 2011
+++ /src/util/system.cpp        Mon Nov 28 05:44:37 2011
@@ -247,7 +247,7 @@
   {
if (mkdir(directory.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP) != 0)
     {
- throw std::runtime_error("System::create_dir: " + directory + ": " + strerror(errno)); + raise_exception(std::runtime_error, "System::create_dir: " << directory << ": " << strerror(errno));
     }
     else
     {
@@ -263,12 +263,14 @@
     }
     else if (dwError == ERROR_PATH_NOT_FOUND)
     {
-      throw std::runtime_error("CreateDirectory: " + directory +
- ": One or more intermediate directories do not exist; this function will only create the final directory in the path.");
+      raise_exception(std::runtime_error,
+                      "CreateDirectory: " << directory <<
+ ": One or more intermediate directories do not exist; this function will only create the final directory in the path.");
     }
     else
     {
- throw std::runtime_error("CreateDirectory: " + directory + ": failed with error " + StringUtil::to_string(dwError));
+      raise_exception(std::runtime_error,
+ "CreateDirectory: " << directory << ": failed with error " << StringUtil::to_string(dwError));
     }
   }
   else
@@ -306,7 +308,7 @@
   }
   else
   {
- throw std::runtime_error("Environment variable $HOME not set, fix that and start again."); + raise_exception(std::runtime_error, "Environment variable $HOME not set, fix that and start again.");
   }
 #endif
 }
@@ -467,7 +469,7 @@

     if (bytes_read != 4096 && !feof(in))
     {
-      throw std::runtime_error("System:checksum: file read error");
+ raise_exception(std::runtime_error, "System:checksum: file read error");
     }

     for (size_t i=0; i < bytes_read; ++i)
@@ -685,41 +687,31 @@
   umask(old_mask);
   if (fd < 0)
   {
-    std::ostringstream out;
-    out << tmpfile.get() << ": " << strerror(errno);
-    throw std::runtime_error(out.str());
+ raise_exception(std::runtime_error, tmpfile.get() << ": " << strerror(errno));
   }

   // write the data to the temporary file
   if (write(fd, content.data(), content.size()) < 0)
   {
-    std::ostringstream out;
-    out << tmpfile.get() << ": " << strerror(errno);
-    throw std::runtime_error(out.str());
+ raise_exception(std::runtime_error, tmpfile.get() << ": " << strerror(errno));
   }

   if (close(fd) < 0)
   {
-    std::ostringstream out;
-    out << tmpfile.get() << ": " << strerror(errno);
-    throw std::runtime_error(out.str());
+ raise_exception(std::runtime_error, tmpfile.get() << ": " << strerror(errno));
   }

   // rename the temporary file to it's final location
   if (rename(tmpfile.get(), filename.c_str()) < 0)
   {
-    std::ostringstream out;
-    out << tmpfile.get() << ": " << strerror(errno);
-    throw std::runtime_error(out.str());
+ raise_exception(std::runtime_error, tmpfile.get() << ": " << strerror(errno));
   }

   // adjust permissions to normal default permissions, as mkstemp
   // might not honor umask
   if (chmod(filename.c_str(), ~old_mask & 0666) < 0)
   {
-    std::ostringstream out;
-    out << tmpfile.get() << ": " << strerror(errno);
-    throw std::runtime_error(out.str());
+ raise_exception(std::runtime_error, tmpfile.get() << ": " << strerror(errno));
   }
 #endif
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]