diff --git a/src/lib/arch/XArch.cpp b/src/lib/arch/XArch.cpp index e377800e..d805c9a8 100644 --- a/src/lib/arch/XArch.cpp +++ b/src/lib/arch/XArch.cpp @@ -23,15 +23,16 @@ // const char* -XArch::what() const throw() +XArch::what() const _NOEXCEPT { + const char* what = std::runtime_error::what(); try { - if (m_what.empty() && m_eval != NULL) { - m_what = m_eval->eval(); + if (strlen(what) == 0 && m_eval != NULL) { + return m_eval->eval().c_str(); } } catch (...) { // ignore } - return m_what.c_str(); + return what; } diff --git a/src/lib/arch/XArch.h b/src/lib/arch/XArch.h index ed9e824a..fc0bdaae 100644 --- a/src/lib/arch/XArch.h +++ b/src/lib/arch/XArch.h @@ -20,6 +20,7 @@ #include "common/common.h" #include "common/stdstring.h" +#include "common/stdexcept.h" //! Generic thread exception /*! @@ -63,19 +64,17 @@ public: }; //! Generic exception architecture dependent library -class XArch : public std::exception { +class XArch : public std::runtime_error { public: - XArch(XArchEval* adoptedEvaluator) : m_eval(adoptedEvaluator) { } - XArch(const std::string& msg) : m_eval(NULL), m_what(msg) { } - XArch(const XArch& e) : m_eval(e.m_eval != NULL ? e.m_eval->clone() : NULL), - m_what(e.m_what) { } - ~XArch() { delete m_eval; } + XArch(XArchEval* adoptedEvaluator) : std::runtime_error(""), m_eval(adoptedEvaluator) { } + XArch(const std::string& msg) : std::runtime_error(msg), m_eval(NULL) { } + XArch(const XArch& e) : std::runtime_error(e.what()), m_eval(e.m_eval != NULL ? e.m_eval->clone() : NULL) { } + ~XArch() _NOEXCEPT { delete m_eval; } - const char* what() const throw(); + virtual const char* what() const _NOEXCEPT; private: XArchEval* m_eval; - mutable std::string m_what; }; // Macro to declare XArch derived types diff --git a/src/lib/base/XBase.cpp b/src/lib/base/XBase.cpp index e873d56e..ddbe631a 100644 --- a/src/lib/base/XBase.cpp +++ b/src/lib/base/XBase.cpp @@ -27,29 +27,30 @@ // XBase::XBase() : - m_what() + std::runtime_error("") { // do nothing } XBase::XBase(const CString& msg) : - m_what(msg) + std::runtime_error(msg) { // do nothing } -XBase::~XBase() +XBase::~XBase() _NOEXCEPT { // do nothing } const char* -XBase::what() const +XBase::what() const _NOEXCEPT { - if (m_what.empty()) { - m_what = getWhat(); + const char* what = std::runtime_error::what(); + if (strlen(what) == 0) { + return getWhat().c_str(); } - return m_what.c_str(); + return what; } CString diff --git a/src/lib/base/XBase.h b/src/lib/base/XBase.h index d265d609..5e576aec 100644 --- a/src/lib/base/XBase.h +++ b/src/lib/base/XBase.h @@ -19,21 +19,22 @@ #pragma once #include "base/String.h" +#include "common/stdexcept.h" //! Exception base class /*! This is the base class of most exception types. */ -class XBase : public std::exception { +class XBase : public std::runtime_error { public: //! Use getWhat() as the result of what() XBase(); //! Use \c msg as the result of what() XBase(const CString& msg); - virtual ~XBase(); + virtual ~XBase() _NOEXCEPT; //! Reason for exception - virtual const char* what() const; + virtual const char* what() const _NOEXCEPT; protected: //! Get a human readable string describing the exception @@ -47,9 +48,6 @@ protected: */ virtual CString format(const char* id, const char* defaultFormat, ...) const throw(); - -private: - mutable CString m_what; }; /*! @@ -63,6 +61,7 @@ class name_ : public super_ { \ public: \ name_() : super_() { } \ name_(const CString& msg) : super_(msg) { } \ + virtual ~name_() _NOEXCEPT { } \ } /*! @@ -76,6 +75,7 @@ class name_ : public super_ { \ public: \ name_() : super_() { } \ name_(const CString& msg) : super_(msg) { } \ + virtual ~name_() _NOEXCEPT { } \ \ protected: \ virtual CString getWhat() const throw(); \ @@ -97,8 +97,9 @@ private: \ public: \ name_() : super_(), m_state(kDone) { } \ name_(const CString& msg) : super_(msg), m_state(kFirst) { } \ + virtual ~name_() _NOEXCEPT { } \ \ - virtual const char* what() const \ + virtual const char* what() const _NOEXCEPT \ { \ if (m_state == kFirst) { \ m_state = kFormat; \ diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 11c32562..c97516e8 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -37,12 +37,12 @@ #include "base/IEventQueue.h" #include "base/TMethodEventJob.h" #include "base/TMethodJob.h" +#include "common/stdexcept.h" #include #include #include #include -#include // // CClient diff --git a/src/lib/common/stdexcept.h b/src/lib/common/stdexcept.h new file mode 100644 index 00000000..340836c8 --- /dev/null +++ b/src/lib/common/stdexcept.h @@ -0,0 +1,23 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2014 Bolton Software Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file COPYING that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +// apple declares _NOEXCEPT +#ifndef _NOEXCEPT +# define _NOEXCEPT throw() +#endif diff --git a/src/lib/net/XSocket.cpp b/src/lib/net/XSocket.cpp index 684946a7..e946efd4 100644 --- a/src/lib/net/XSocket.cpp +++ b/src/lib/net/XSocket.cpp @@ -24,7 +24,7 @@ // XSocketAddress::XSocketAddress(EError error, - const CString& hostname, int port) throw() : + const CString& hostname, int port) _NOEXCEPT : m_error(error), m_hostname(hostname), m_port(port) diff --git a/src/lib/net/XSocket.h b/src/lib/net/XSocket.h index ebd74e5f..7194ada3 100644 --- a/src/lib/net/XSocket.h +++ b/src/lib/net/XSocket.h @@ -41,7 +41,8 @@ public: kBadPort //!< The port is invalid }; - XSocketAddress(EError, const CString& hostname, int port) throw(); + XSocketAddress(EError, const CString& hostname, int port) _NOEXCEPT; + virtual ~XSocketAddress() _NOEXCEPT { } //! @name accessors //@{ diff --git a/src/lib/server/Config.cpp b/src/lib/server/Config.cpp index 333ed606..c04e5e41 100644 --- a/src/lib/server/Config.cpp +++ b/src/lib/server/Config.cpp @@ -2313,7 +2313,7 @@ XConfigRead::XConfigRead(const CConfigReadContext& context, // do nothing } -XConfigRead::~XConfigRead() +XConfigRead::~XConfigRead() _NOEXCEPT { // do nothing } diff --git a/src/lib/server/Config.h b/src/lib/server/Config.h index 9f7f5d68..cdd364bd 100644 --- a/src/lib/server/Config.h +++ b/src/lib/server/Config.h @@ -534,7 +534,7 @@ public: XConfigRead(const CConfigReadContext& context, const CString&); XConfigRead(const CConfigReadContext& context, const char* errorFmt, const CString& arg); - ~XConfigRead(); + virtual ~XConfigRead() _NOEXCEPT; protected: // XBase overrides diff --git a/src/lib/server/Server.cpp b/src/lib/server/Server.cpp index 564f542c..55a1fb2d 100644 --- a/src/lib/server/Server.cpp +++ b/src/lib/server/Server.cpp @@ -38,12 +38,12 @@ #include "base/IEventQueue.h" #include "base/Log.h" #include "base/TMethodEventJob.h" +#include "common/stdexcept.h" #include #include #include #include -#include // // CServer diff --git a/src/lib/synergy/FileChunker.cpp b/src/lib/synergy/FileChunker.cpp index 6dbb7801..e27ba8a5 100644 --- a/src/lib/synergy/FileChunker.cpp +++ b/src/lib/synergy/FileChunker.cpp @@ -24,10 +24,10 @@ #include "base/EventTypes.h" #include "base/Log.h" #include "base/Stopwatch.h" +#include "common/stdexcept.h" #include #include -#include #define PAUSE_TIME_HACK 0.1 diff --git a/src/lib/synergy/PlatformScreen.h b/src/lib/synergy/PlatformScreen.h index 24214924..c457abb0 100644 --- a/src/lib/synergy/PlatformScreen.h +++ b/src/lib/synergy/PlatformScreen.h @@ -16,11 +16,10 @@ * along with this program. If not, see . */ -#pragma once +#pragma once #include "synergy/IPlatformScreen.h" - -#include +#include "common/stdexcept.h" //! Base screen implementation /*! diff --git a/src/lib/synergy/XScreen.cpp b/src/lib/synergy/XScreen.cpp index a4963fac..e62991f3 100644 --- a/src/lib/synergy/XScreen.cpp +++ b/src/lib/synergy/XScreen.cpp @@ -50,7 +50,7 @@ XScreenUnavailable::XScreenUnavailable(double timeUntilRetry) : // do nothing } -XScreenUnavailable::~XScreenUnavailable() +XScreenUnavailable::~XScreenUnavailable() _NOEXCEPT { // do nothing } diff --git a/src/lib/synergy/XScreen.h b/src/lib/synergy/XScreen.h index 9ea55abe..780a98cb 100644 --- a/src/lib/synergy/XScreen.h +++ b/src/lib/synergy/XScreen.h @@ -47,7 +47,7 @@ public: trying to open the screen again. */ XScreenUnavailable(double timeUntilRetry); - virtual ~XScreenUnavailable(); + virtual ~XScreenUnavailable() _NOEXCEPT; //! @name manipulators //@{ diff --git a/src/lib/synergy/XSynergy.h b/src/lib/synergy/XSynergy.h index 4b2ccab3..e288b53d 100644 --- a/src/lib/synergy/XSynergy.h +++ b/src/lib/synergy/XSynergy.h @@ -63,6 +63,7 @@ a client that is already connected. class XDuplicateClient : public XSynergy { public: XDuplicateClient(const CString& name); + virtual ~XDuplicateClient() _NOEXCEPT { } //! @name accessors //@{ @@ -88,6 +89,7 @@ unknown to the server. class XUnknownClient : public XSynergy { public: XUnknownClient(const CString& name); + virtual ~XUnknownClient() _NOEXCEPT { } //! @name accessors //@{ @@ -114,6 +116,7 @@ exit(int). class XExitApp : public XSynergy { public: XExitApp(int code); + virtual ~XExitApp() _NOEXCEPT { } //! Get the exit code int getCode() const throw(); diff --git a/src/test/global/TestEventQueue.cpp b/src/test/global/TestEventQueue.cpp index 23000e87..91a615fa 100644 --- a/src/test/global/TestEventQueue.cpp +++ b/src/test/global/TestEventQueue.cpp @@ -20,8 +20,7 @@ #include "base/Log.h" #include "base/TMethodEventJob.h" #include "base/SimpleEventQueueBuffer.h" - -#include +#include "common/stdexcept.h" void CTestEventQueue::raiseQuitEvent() diff --git a/src/test/integtests/net/NetworkTests.cpp b/src/test/integtests/net/NetworkTests.cpp index 2621c74f..214082ba 100644 --- a/src/test/integtests/net/NetworkTests.cpp +++ b/src/test/integtests/net/NetworkTests.cpp @@ -37,9 +37,9 @@ #include "base/TMethodEventJob.h" #include "base/TMethodJob.h" #include "base/Log.h" +#include "common/stdexcept.h" #include "test/global/gtest.h" -#include #include #include #include