Don't catch unknown exceptions if we are only going to rethrow them.
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 26 Apr 2010 12:34:39 +0000 (14:34 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 26 Apr 2010 12:34:39 +0000 (14:34 +0200)
Rethrowing hides the real source of the exception.

src/command_client.cpp
src/command_server.cpp
src/socket_server.cpp
src/socket_wrapper.cpp
test/cmdgroup.cpp
test/newserver.cpp
test/serialize.cpp
test/simplecmd.cpp
test/timeout.cpp

index 9945a5a..5d618b2 100644 (file)
@@ -72,10 +72,6 @@ command_client::command_client(client_connection* _c, long long _command_timeout
             // store a copy of the exception that you can find out details about the error later
             constructorException = e.clone();
         }
-        catch (...)
-        {
-            throw;
-        }
     }
 }
 
@@ -271,8 +267,6 @@ void command_client::send_command(command* cmd, result_container &res)
         msg << "archive_exception while serializing on client-side, code " << e.code << " (" << e.what() << ")";
         throw t2n_serialization_error(msg.str());
     }
-    catch(...)
-        { throw; }
 
     std::ostream* ostr;
     if ((ostr=c->get_logstream(fulldebug))!=NULL)
@@ -297,8 +291,6 @@ void command_client::send_command(command* cmd, result_container &res)
         msg << "archive_exception while deserializing on client-side, code " << e.code << " (" << e.what() << ")";
         throw t2n_serialization_error(msg.str());
     }
-    catch(...)
-        { throw; }
 
     if ((ostr=c->get_logstream(fulldebug))!=NULL)
     {
index 2bb6521..1db24a4 100644 (file)
@@ -102,8 +102,6 @@ void command_server::handle_packet(const std::string& packet, server_connection*
                "code " << e.code << " (" << e.what() << ")";
         res.set_exception(new t2n_serialization_error(msg.str()));
     }
-    catch(...)
-        { throw; }
 
     if (!res.has_exception())
     {
@@ -125,8 +123,6 @@ void command_server::handle_packet(const std::string& packet, server_connection*
             }
             catch (t2n_exception &e)
                 { res.set_exception(e.clone()); }
-            catch (...)
-                { throw; }
         }
         else
         {
@@ -154,8 +150,6 @@ void command_server::handle_packet(const std::string& packet, server_connection*
         res.set_exception(new t2n_serialization_error(msg.str()));
         oa << res;
     }
-    catch(...)
-        { throw; }
 
     std::ostream* ostr;
     if ((ostr=s.get_logstream(fulldebug))!=NULL)
@@ -196,8 +190,6 @@ void command_server::handle(long long usec_timeout, long long* usec_timeout_rema
                     // shut down a connection with transfer errors (usually write errors)
                     conn->close();
                 }
-                catch(...)
-                    { throw; }
             }
         }
     }
index 7c6f244..35bb314 100644 (file)
@@ -277,8 +277,6 @@ bool socket_server::fill_connection_buffers()
             }
             catch (t2n_transfer_error &e)
                 { i->second->close(); }
-            catch(...)
-                { throw; }
         }
 
     return data_found;
index 89521bc..50ec75f 100644 (file)
@@ -87,10 +87,6 @@ bool ReconnectSocketWrapper::handle(command_client* stubBase, boost::function< v
 
             // otherwise ignore the exception and reconnect in the next iteration
         }
-        catch(...)
-        {
-            throw;
-        }
 
         tries++;
     }
@@ -141,10 +137,6 @@ bool ReconnectIgnoreFailureSocketWrapper::handle(command_client* stubBase, boost
         {
             // ignore
         }
-        catch(...)
-        {
-            throw;
-        }
     }
 
     return false;
index 1c30cc3..942fd88 100644 (file)
@@ -271,8 +271,6 @@ BOOST_AUTO_TEST_CASE(WrongGroup)
             }
             catch(t2n_command_error &e)
                 { ret=e.what(); }
-            catch(...)
-                { throw; }
 
             string expected_what="illegal command of type ";
 
index 32f4d96..5fa21b4 100644 (file)
@@ -193,8 +193,6 @@ BOOST_AUTO_TEST_CASE(NewServerSocket)
             }
             catch(t2n_transfer_error &e)
                 { errormsg=e.what(); }
-            catch(...)
-                { throw; }
 
             bool test_fine=false;
             if (errormsg == "write() returned Bad file descriptor"
index 598ac4b..3019952 100644 (file)
@@ -171,8 +171,6 @@ BOOST_AUTO_TEST_CASE(ClientSerializeErr)
             }
             catch(t2n_serialization_error &e)
                 { errormsg=e.what(); }
-            catch(...)
-                { throw; }
 
             BOOST_CHECK_EQUAL(string("archive_exception while serializing on client-side, code 2 (unregistered class)"),errormsg);
         }
index 11de9ca..97fa6da 100644 (file)
@@ -224,8 +224,6 @@ BOOST_AUTO_TEST_CASE(SimpleException)
             }
             catch(t2n_runtime_error &e)
                 { ret=e.what(); }
-            catch(...)
-                { throw; }
 
             BOOST_CHECK_EQUAL(string("throw me around"),ret);
         }
index 8f67cac..c85d43e 100644 (file)
@@ -370,8 +370,6 @@ BOOST_AUTO_TEST_CASE(CommandTimeout)
             }
             catch(t2n_transfer_error &e)
             { errormsg=e.what(); }
-            catch(...)
-            { throw; }
 
             BOOST_CHECK_EQUAL(string("timeout exceeded"),errormsg);
         }
@@ -449,8 +447,6 @@ BOOST_AUTO_TEST_CASE(CommandSlowResponse)
             }
             catch(t2n_transfer_error &e)
             { errormsg=e.what(); }
-            catch(...)
-            { throw; }
 
             BOOST_CHECK_EQUAL(string("timeout exceeded"),errormsg);
         }
@@ -506,8 +502,6 @@ BOOST_AUTO_TEST_CASE(DisconnectOnWrite)
             }
             catch(t2n_transfer_error &e)
             { errormsg=e.what(); }
-            catch(...)
-            { throw; }
 
             BOOST_CHECK_EQUAL(string("write() returned Broken pipe"),errormsg);
         }
@@ -569,8 +563,6 @@ BOOST_AUTO_TEST_CASE(WriteTwice)
             }
             catch(t2n_transfer_error &e)
             { errormsg=e.what(); }
-            catch(...)
-            { throw; }
 
             BOOST_CHECK_EQUAL(string("write() returned Broken pipe"),errormsg);
         }