refactor: XArch Classes => Arch Exception Classes

This commit is contained in:
sithlord48
2025-08-07 17:35:24 -04:00
committed by Nick Bolton
parent 8929f85bf7
commit 85d89f9846
27 changed files with 336 additions and 336 deletions

View File

@ -0,0 +1,205 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#pragma once
#include "common/Common.h"
#include <stdexcept>
#include <string>
//! Generic thread exception
/*!
Exceptions derived from this class are used by the multithreading
library to perform stack unwinding when a thread terminates. These
exceptions must always be rethrown by clients when caught.
*/
class ThreadException : public std::exception
{
};
//! Thread exception to cancel
/*!
Thrown to cancel a thread. Clients must not throw this type, but
must rethrow it if caught (by ThreadCancelException, ThreadException, or ...).
*/
class ThreadCancelException : public ThreadException
{
};
/*!
\def RETHROW_THREADEXCEPTION
Convenience macro to rethrow an ThreadException exception but ignore other
exceptions. Put this in your catch (...) handler after necessary
cleanup but before leaving or returning from the handler.
*/
#define RETHROW_THREADEXCEPTION \
try { \
throw; \
} catch (ThreadException &) { \
throw; \
} catch (...) { \
}
//! Generic network exception
/*!
Exceptions derived from this class are used by the networking
library to indicate various errors.
*/
class ArchNetworkException : public std::runtime_error
{
using std::runtime_error::runtime_error;
};
//! Operation was interrupted
class ArchNetworkInterruptedException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Network insufficient permission
class ArchNetworkAccessException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Network insufficient resources
class ArchNetworkResourceException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! No support for requested network resource/service
class ArchNetworkSupportException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Network I/O error
class ArchNetworkIOException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Network address is unavailable or not local
class ArchNetworkNoAddressException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Network address in use
class ArchNetworkAddressInUseException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! No route to address
class ArchNetworkNoRouteException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Socket not connected
class ArchNetworkNotConnectedException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Remote read end of socket has closed
class ArchNetworkShutdownException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Remote end of socket has disconnected
class ArchNetworkDisconnectedException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Remote end of socket refused connection
class ArchNetworkConnectionRefusedException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Remote end of socket is not responding
class ArchNetworkTimedOutException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! Generic network name lookup erros
class ArchNetworkNameException : public ArchNetworkException
{
using ArchNetworkException::ArchNetworkException;
};
//! The named host is unknown
class ArchNetworkNameUnknownException : public ArchNetworkNameException
{
using ArchNetworkNameException::ArchNetworkNameException;
};
//! The named host is known but has no address
class ArchNetworkNameNoAddressException : public ArchNetworkNameException
{
using ArchNetworkNameException::ArchNetworkNameException;
};
//! Non-recoverable name server error
class ArchNetworkNameFailureException : public ArchNetworkNameException
{
using ArchNetworkNameException::ArchNetworkNameException;
};
//! Temporary name server error
class ArchNetworkNameUnavailableException : public ArchNetworkNameException
{
using ArchNetworkNameException::ArchNetworkNameException;
};
//! The named host is known but no supported address
class ArchNetworkNameUnsupportedException : public ArchNetworkNameException
{
using ArchNetworkNameException::ArchNetworkNameException;
};
//! Generic daemon exception
/*!
Exceptions derived from this class are used by the daemon
library to indicate various errors.
*/
class ArchDaemonException : public std::runtime_error
{
using std::runtime_error::runtime_error;
};
//! Could not daemonize
class ArchDaemonFailedException : public ArchDaemonException
{
using ArchDaemonException::ArchDaemonException;
};
//! Could not install daemon
class ArchDaemonInstallException : public ArchDaemonException
{
using ArchDaemonException::ArchDaemonException;
};
//! Could not uninstall daemon
class ArchDaemonUninstallFailedException : public ArchDaemonException
{
using ArchDaemonException::ArchDaemonException;
};
//! Attempted to uninstall a daemon that was not installed
class ArchDaemonUninstallNotInstalledException : public ArchDaemonFailedException
{
using ArchDaemonFailedException::ArchDaemonFailedException;
};

View File

@ -40,13 +40,13 @@ add_library(arch STATIC ${PLATFORM_CODE}
Arch.h
ArchDaemonNone.cpp
ArchDaemonNone.h
ArchException.h
IArchDaemon.h
IArchLog.h
IArchMultithread.h
IArchNetwork.h
ArchString.cpp
ArchString.h
XArch.h
)
if(UNIX)

View File

@ -37,7 +37,7 @@ public:
start when the current user logs in. If \p dependencies is not nullptr
then it's a concatenation of NUL terminated other daemon names
followed by a NUL; the daemon will be configured to startup after
the listed daemons. Throws an \c XArchDaemon exception on failure.
the listed daemons. Throws an \c ArchDaemonException exception on failure.
*/
virtual void installDaemon(
const char *name, const char *description, const char *pathname, const char *commandLine, const char *dependencies
@ -45,7 +45,7 @@ public:
//! Uninstall daemon
/*!
Uninstall a daemon. Throws an \c XArchDaemon on failure.
Uninstall a daemon. Throws an \c ArchDaemonException on failure.
*/
virtual void uninstallDaemon(const char *name) = 0;
@ -63,7 +63,7 @@ public:
//! Daemonize the process
/*!
Daemonize. Throw XArchDaemonFailed on error. \c name is the name
Daemonize. Throw ArchDaemonFailedException on error. \c name is the name
of the daemon. Once daemonized, \c func is invoked and daemonize
returns when and what it does.

View File

@ -213,7 +213,7 @@ public:
//! Check error on socket
/*!
If the socket \c s is in an error state then throws an appropriate
XArchNetwork exception.
ArchNetworkException exception.
*/
virtual void throwErrorOnSocket(ArchSocket s) = 0;

View File

@ -1,205 +0,0 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#pragma once
#include "common/Common.h"
#include <stdexcept>
#include <string>
//! Generic thread exception
/*!
Exceptions derived from this class are used by the multithreading
library to perform stack unwinding when a thread terminates. These
exceptions must always be rethrown by clients when caught.
*/
class XThread : public std::exception
{
};
//! Thread exception to cancel
/*!
Thrown to cancel a thread. Clients must not throw this type, but
must rethrow it if caught (by XThreadCancel, XThread, or ...).
*/
class XThreadCancel : public XThread
{
};
/*!
\def RETHROW_XTHREAD
Convenience macro to rethrow an XThread exception but ignore other
exceptions. Put this in your catch (...) handler after necessary
cleanup but before leaving or returning from the handler.
*/
#define RETHROW_XTHREAD \
try { \
throw; \
} catch (XThread &) { \
throw; \
} catch (...) { \
}
//! Generic network exception
/*!
Exceptions derived from this class are used by the networking
library to indicate various errors.
*/
class XArchNetwork : public std::runtime_error
{
using std::runtime_error::runtime_error;
};
//! Operation was interrupted
class XArchNetworkInterrupted : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Network insufficient permission
class XArchNetworkAccess : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Network insufficient resources
class XArchNetworkResource : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! No support for requested network resource/service
class XArchNetworkSupport : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Network I/O error
class XArchNetworkIO : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Network address is unavailable or not local
class XArchNetworkNoAddress : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Network address in use
class XArchNetworkAddressInUse : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! No route to address
class XArchNetworkNoRoute : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Socket not connected
class XArchNetworkNotConnected : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Remote read end of socket has closed
class XArchNetworkShutdown : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Remote end of socket has disconnected
class XArchNetworkDisconnected : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Remote end of socket refused connection
class XArchNetworkConnectionRefused : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Remote end of socket is not responding
class XArchNetworkTimedOut : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! Generic network name lookup erros
class XArchNetworkName : public XArchNetwork
{
using XArchNetwork::XArchNetwork;
};
//! The named host is unknown
class XArchNetworkNameUnknown : public XArchNetworkName
{
using XArchNetworkName::XArchNetworkName;
};
//! The named host is known but has no address
class XArchNetworkNameNoAddress : public XArchNetworkName
{
using XArchNetworkName::XArchNetworkName;
};
//! Non-recoverable name server error
class XArchNetworkNameFailure : public XArchNetworkName
{
using XArchNetworkName::XArchNetworkName;
};
//! Temporary name server error
class XArchNetworkNameUnavailable : public XArchNetworkName
{
using XArchNetworkName::XArchNetworkName;
};
//! The named host is known but no supported address
class XArchNetworkNameUnsupported : public XArchNetworkName
{
using XArchNetworkName::XArchNetworkName;
};
//! Generic daemon exception
/*!
Exceptions derived from this class are used by the daemon
library to indicate various errors.
*/
class XArchDaemon : public std::runtime_error
{
using std::runtime_error::runtime_error;
};
//! Could not daemonize
class XArchDaemonFailed : public XArchDaemon
{
using XArchDaemon::XArchDaemon;
};
//! Could not install daemon
class XArchDaemonInstallFailed : public XArchDaemon
{
using XArchDaemon::XArchDaemon;
};
//! Could not uninstall daemon
class XArchDaemonUninstallFailed : public XArchDaemon
{
using XArchDaemon::XArchDaemon;
};
//! Attempted to uninstall a daemon that was not installed
class XArchDaemonUninstallNotInstalled : public XArchDaemonFailed
{
using XArchDaemonFailed::XArchDaemonFailed;
};

View File

@ -8,7 +8,7 @@
#include "arch/unix/ArchDaemonUnix.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "arch/unix/XArchUnix.h"
#include "base/Log.h"
@ -58,7 +58,7 @@ int ArchDaemonUnix::daemonize(const char *name, DaemonFunc const &func)
switch (fork()) {
case -1:
// failed
throw XArchDaemonFailed(errorToString(errno));
throw ArchDaemonFailedException(errorToString(errno));
case 0:
// child

View File

@ -8,7 +8,7 @@
#include "arch/unix/ArchMultithreadPosix.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include <cerrno>
#include <signal.h>
@ -584,7 +584,7 @@ void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread)
// unwind thread's stack if cancelling
if (cancel) {
throw XThreadCancel();
throw ThreadCancelException();
}
}
@ -620,7 +620,7 @@ void ArchMultithreadPosix::doThreadFunc(ArchThread thread)
result = (*thread->m_func)(thread->m_userData);
}
catch (XThreadCancel &) {
catch (ThreadCancelException &) {
// client called cancel()
// set base value
result = nullptr;

View File

@ -8,7 +8,7 @@
#include "arch/unix/ArchNetworkBSD.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "arch/unix/ArchMultithreadPosix.h"
#include "arch/unix/XArchUnix.h"
@ -745,11 +745,11 @@ const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
switch (err) {
case EINTR:
ARCH->testCancelThread();
throw XArchNetworkInterrupted(errorToString(err));
throw ArchNetworkInterruptedException(errorToString(err));
case EACCES:
case EPERM:
throw XArchNetworkAccess(errorToString(err));
throw ArchNetworkAccessException(errorToString(err));
case ENFILE:
case EMFILE:
@ -760,7 +760,7 @@ const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
#if defined(ENOSR)
case ENOSR:
#endif
throw XArchNetworkResource(errorToString(err));
throw ArchNetworkResourceException(errorToString(err));
case EPROTOTYPE:
case EPROTONOSUPPORT:
@ -774,40 +774,40 @@ const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
#if defined(ENOPKG)
case ENOPKG:
#endif
throw XArchNetworkSupport(errorToString(err));
throw ArchNetworkSupportException(errorToString(err));
case EIO:
throw XArchNetworkIO(errorToString(err));
throw ArchNetworkIOException(errorToString(err));
case EADDRNOTAVAIL:
throw XArchNetworkNoAddress(errorToString(err));
throw ArchNetworkNoAddressException(errorToString(err));
case EADDRINUSE:
throw XArchNetworkAddressInUse(errorToString(err));
throw ArchNetworkAddressInUseException(errorToString(err));
case EHOSTUNREACH:
case ENETUNREACH:
throw XArchNetworkNoRoute(errorToString(err));
throw ArchNetworkNoRouteException(errorToString(err));
case ENOTCONN:
throw XArchNetworkNotConnected(errorToString(err));
throw ArchNetworkNotConnectedException(errorToString(err));
case EPIPE:
throw XArchNetworkShutdown(errorToString(err));
throw ArchNetworkShutdownException(errorToString(err));
case ECONNABORTED:
case ECONNRESET:
throw XArchNetworkDisconnected(errorToString(err));
throw ArchNetworkDisconnectedException(errorToString(err));
case ECONNREFUSED:
throw XArchNetworkConnectionRefused(errorToString(err));
throw ArchNetworkConnectionRefusedException(errorToString(err));
case EHOSTDOWN:
case ETIMEDOUT:
throw XArchNetworkTimedOut(errorToString(err));
throw ArchNetworkTimedOutException(errorToString(err));
default:
throw XArchNetwork(errorToString(err));
throw ArchNetworkException(errorToString(err));
}
}
@ -821,18 +821,18 @@ const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
switch (err) {
case HOST_NOT_FOUND:
throw XArchNetworkNameUnknown(s_msg[0]);
throw ArchNetworkNameUnknownException(s_msg[0]);
case NO_DATA:
throw XArchNetworkNameNoAddress(s_msg[1]);
throw ArchNetworkNameNoAddressException(s_msg[1]);
case NO_RECOVERY:
throw XArchNetworkNameFailure(s_msg[2]);
throw ArchNetworkNameFailureException(s_msg[2]);
case TRY_AGAIN:
throw XArchNetworkNameUnavailable(s_msg[3]);
throw ArchNetworkNameUnavailableException(s_msg[3]);
default:
throw XArchNetworkName(s_msg[4]);
throw ArchNetworkNameException(s_msg[4]);
}
}

View File

@ -8,7 +8,7 @@
#include "arch/win32/ArchDaemonWindows.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "arch/win32/ArchMiscWindows.h"
#include "arch/win32/XArchWindows.h"
#include "base/Log.h"
@ -51,7 +51,7 @@ UINT ArchDaemonWindows::getDaemonQuitMessage()
void ArchDaemonWindows::daemonFailed(int result)
{
assert(s_daemon != nullptr);
throw XArchDaemonRunFailed(result);
throw ArchDaemonRunException(result);
}
void ArchDaemonWindows::installDaemon(
@ -64,7 +64,7 @@ void ArchDaemonWindows::installDaemon(
SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_WRITE);
if (mgr == nullptr) {
// can't open service manager
throw XArchDaemonInstallFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonInstallException(windowsErrorToString(GetLastError()));
}
// create the service
@ -78,7 +78,7 @@ void ArchDaemonWindows::installDaemon(
DWORD err = GetLastError();
if (err != ERROR_SERVICE_EXISTS) {
CloseServiceHandle(mgr);
throw XArchDaemonInstallFailed(windowsErrorToString(err));
throw ArchDaemonInstallException(windowsErrorToString(err));
}
} else {
// done with service (but only try to close if not null)
@ -99,7 +99,7 @@ void ArchDaemonWindows::installDaemon(
} catch (...) {
// ignore
}
throw XArchDaemonInstallFailed(windowsErrorToString(err));
throw ArchDaemonInstallException(windowsErrorToString(err));
}
// set the description
@ -116,7 +116,7 @@ void ArchDaemonWindows::installDaemon(
} catch (...) {
// ignore
}
throw XArchDaemonInstallFailed(windowsErrorToString(err));
throw ArchDaemonInstallException(windowsErrorToString(err));
}
ArchMiscWindows::setValue(key, _T("CommandLine"), commandLine);
@ -140,7 +140,7 @@ void ArchDaemonWindows::uninstallDaemon(const char *name)
SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_WRITE);
if (mgr == nullptr) {
// can't open service manager
throw XArchDaemonUninstallFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonUninstallFailedException(windowsErrorToString(GetLastError()));
}
// open the service. oddly, you must open a service to delete it.
@ -149,9 +149,9 @@ void ArchDaemonWindows::uninstallDaemon(const char *name)
DWORD err = GetLastError();
CloseServiceHandle(mgr);
if (err != ERROR_SERVICE_DOES_NOT_EXIST) {
throw XArchDaemonUninstallFailed(windowsErrorToString(err));
throw ArchDaemonUninstallFailedException(windowsErrorToString(err));
}
throw XArchDaemonUninstallNotInstalled(windowsErrorToString(err));
throw ArchDaemonUninstallNotInstalledException(windowsErrorToString(err));
}
// stop the service. we don't care if we fail.
@ -184,9 +184,9 @@ void ArchDaemonWindows::uninstallDaemon(const char *name)
return;
}
if (err != ERROR_SERVICE_MARKED_FOR_DELETE) {
throw XArchDaemonUninstallFailed(windowsErrorToString(err));
throw ArchDaemonUninstallFailedException(windowsErrorToString(err));
}
throw XArchDaemonUninstallNotInstalled(windowsErrorToString(err));
throw ArchDaemonUninstallNotInstalledException(windowsErrorToString(err));
}
}
@ -211,7 +211,7 @@ int ArchDaemonWindows::daemonize(const char *name, DaemonFunc const &func)
if (StartServiceCtrlDispatcher(entry) == 0) {
// StartServiceCtrlDispatcher failed
s_daemon = nullptr;
throw XArchDaemonFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonFailedException(windowsErrorToString(GetLastError()));
}
s_daemon = nullptr;
@ -472,7 +472,7 @@ void ArchDaemonWindows::serviceMain(DWORD argc, LPTSTR *argvIn)
try {
// invoke daemon function
m_daemonResult = m_daemonFunc(static_cast<int>(argc), argv);
} catch (XArchDaemonRunFailed &e) {
} catch (ArchDaemonRunException &e) {
setStatusError(e.m_result);
m_daemonResult = -1;
} catch (...) {
@ -560,7 +560,7 @@ void ArchDaemonWindows::start(const char *name)
// open service manager
SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_READ);
if (mgr == nullptr) {
throw XArchDaemonFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonFailedException(windowsErrorToString(GetLastError()));
}
// open the service
@ -568,12 +568,12 @@ void ArchDaemonWindows::start(const char *name)
if (service == nullptr) {
CloseServiceHandle(mgr);
throw XArchDaemonFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonFailedException(windowsErrorToString(GetLastError()));
}
// start the service
if (!StartService(service, 0, nullptr)) {
throw XArchDaemonFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonFailedException(windowsErrorToString(GetLastError()));
}
}
@ -582,7 +582,7 @@ void ArchDaemonWindows::stop(const char *name)
// open service manager
SC_HANDLE mgr = OpenSCManager(nullptr, nullptr, GENERIC_READ);
if (mgr == nullptr) {
throw XArchDaemonFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonFailedException(windowsErrorToString(GetLastError()));
}
// open the service
@ -590,7 +590,7 @@ void ArchDaemonWindows::stop(const char *name)
if (service == nullptr) {
CloseServiceHandle(mgr);
throw XArchDaemonFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonFailedException(windowsErrorToString(GetLastError()));
}
// ask the service to stop, asynchronously
@ -598,7 +598,7 @@ void ArchDaemonWindows::stop(const char *name)
if (!ControlService(service, SERVICE_CONTROL_STOP, &ss)) {
DWORD dwErrCode = GetLastError();
if (dwErrCode != ERROR_SERVICE_NOT_ACTIVE) {
throw XArchDaemonFailed(windowsErrorToString(GetLastError()));
throw ArchDaemonFailedException(windowsErrorToString(GetLastError()));
}
}
}

View File

@ -104,10 +104,10 @@ private:
void stop(const char *name);
private:
class XArchDaemonRunFailed
class ArchDaemonRunException
{
public:
XArchDaemonRunFailed(int result) : m_result(result)
ArchDaemonRunException(int result) : m_result(result)
{
}

View File

@ -11,7 +11,7 @@
#include "arch/win32/ArchMultithreadWindows.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include <process.h>
@ -577,7 +577,7 @@ void ArchMultithreadWindows::testCancelThreadImpl(ArchThreadImpl *thread)
// unwind thread's stack if cancelling
if (cancel) {
throw XThreadCancel();
throw ThreadCancelException();
}
}
@ -606,7 +606,7 @@ void ArchMultithreadWindows::doThreadFunc(ArchThread thread)
result = (*thread->m_func)(thread->m_userData);
}
catch (XThreadCancel &) {
catch (ThreadCancelException &) {
// client called cancel()
} catch (...) {
// note -- don't catch (...) to avoid masking bugs

View File

@ -7,8 +7,8 @@
#include "arch/win32/ArchNetworkWinsock.h"
#include "arch/Arch.h"
#include "arch/ArchException.h"
#include "arch/IArchMultithread.h"
#include "arch/XArch.h"
#include "arch/win32/ArchMultithreadWindows.h"
#include "arch/win32/XArchWindows.h"
@ -65,7 +65,7 @@ static FARPROC netGetProcAddress(HMODULE module, LPCSTR name)
{
FARPROC func = ::GetProcAddress(module, name);
if (!func) {
throw XArchNetworkSupport("");
throw ArchNetworkSupportException("");
}
return func;
}
@ -110,19 +110,19 @@ void ArchNetworkWinsock::init()
try {
initModule((HMODULE)::LoadLibrary(s_library[i]));
return;
} catch (XArchNetwork &) {
} catch (ArchNetworkException &) {
// ignore
}
}
// can't initialize any library
throw XArchNetworkSupport("Cannot load winsock library");
throw ArchNetworkSupportException("Cannot load winsock library");
}
void ArchNetworkWinsock::initModule(HMODULE module)
{
if (module == nullptr) {
throw XArchNetworkSupport("");
throw ArchNetworkSupportException("");
}
// get startup function address
@ -134,7 +134,7 @@ void ArchNetworkWinsock::initModule(HMODULE module)
WSADATA data;
int err = startup(version, &data);
if (data.wVersion != version) {
throw XArchNetworkSupport(winsockErrorToString(err));
throw ArchNetworkSupportException(winsockErrorToString(err));
}
if (err != 0) {
// some other initialization error
@ -844,12 +844,12 @@ bool ArchNetworkWinsock::isEqualAddr(ArchNetAddress a, ArchNetAddress b)
{
switch (err) {
case WSAEACCES:
throw XArchNetworkAccess(winsockErrorToString(err));
throw ArchNetworkAccessException(winsockErrorToString(err));
case WSAEMFILE:
case WSAENOBUFS:
case WSAENETDOWN:
throw XArchNetworkResource(winsockErrorToString(err));
throw ArchNetworkResourceException(winsockErrorToString(err));
case WSAEPROTOTYPE:
case WSAEPROTONOSUPPORT:
@ -863,50 +863,50 @@ bool ArchNetworkWinsock::isEqualAddr(ArchNetAddress a, ArchNetAddress b)
case WSANOTINITIALISED:
case WSAVERNOTSUPPORTED:
case WSASYSNOTREADY:
throw XArchNetworkSupport(winsockErrorToString(err));
throw ArchNetworkSupportException(winsockErrorToString(err));
case WSAEADDRNOTAVAIL:
throw XArchNetworkNoAddress(winsockErrorToString(err));
throw ArchNetworkNoAddressException(winsockErrorToString(err));
case WSAEADDRINUSE:
throw XArchNetworkAddressInUse(winsockErrorToString(err));
throw ArchNetworkAddressInUseException(winsockErrorToString(err));
case WSAEHOSTUNREACH:
case WSAENETUNREACH:
throw XArchNetworkNoRoute(winsockErrorToString(err));
throw ArchNetworkNoRouteException(winsockErrorToString(err));
case WSAENOTCONN:
throw XArchNetworkNotConnected(winsockErrorToString(err));
throw ArchNetworkNotConnectedException(winsockErrorToString(err));
case WSAEDISCON:
throw XArchNetworkShutdown(winsockErrorToString(err));
throw ArchNetworkShutdownException(winsockErrorToString(err));
case WSAENETRESET:
case WSAECONNABORTED:
case WSAECONNRESET:
throw XArchNetworkDisconnected(winsockErrorToString(err));
throw ArchNetworkDisconnectedException(winsockErrorToString(err));
case WSAECONNREFUSED:
throw XArchNetworkConnectionRefused(winsockErrorToString(err));
throw ArchNetworkConnectionRefusedException(winsockErrorToString(err));
case WSAEHOSTDOWN:
case WSAETIMEDOUT:
throw XArchNetworkTimedOut(winsockErrorToString(err));
throw ArchNetworkTimedOutException(winsockErrorToString(err));
case WSAHOST_NOT_FOUND:
throw XArchNetworkNameUnknown(winsockErrorToString(err));
throw ArchNetworkNameUnknownException(winsockErrorToString(err));
case WSANO_DATA:
throw XArchNetworkNameNoAddress(winsockErrorToString(err));
throw ArchNetworkNameNoAddressException(winsockErrorToString(err));
case WSANO_RECOVERY:
throw XArchNetworkNameFailure(winsockErrorToString(err));
throw ArchNetworkNameFailureException(winsockErrorToString(err));
case WSATRY_AGAIN:
throw XArchNetworkNameUnavailable(winsockErrorToString(err));
throw ArchNetworkNameUnavailableException(winsockErrorToString(err));
default:
throw XArchNetwork(winsockErrorToString(err));
throw ArchNetworkException(winsockErrorToString(err));
}
}
@ -914,18 +914,18 @@ bool ArchNetworkWinsock::isEqualAddr(ArchNetAddress a, ArchNetAddress b)
{
switch (err) {
case WSAHOST_NOT_FOUND:
throw XArchNetworkNameUnknown(winsockErrorToString(err));
throw ArchNetworkNameUnknownException(winsockErrorToString(err));
case WSANO_DATA:
throw XArchNetworkNameNoAddress(winsockErrorToString(err));
throw ArchNetworkNameNoAddressException(winsockErrorToString(err));
case WSANO_RECOVERY:
throw XArchNetworkNameFailure(winsockErrorToString(err));
throw ArchNetworkNameFailureException(winsockErrorToString(err));
case WSATRY_AGAIN:
throw XArchNetworkNameUnavailable(winsockErrorToString(err));
throw ArchNetworkNameUnavailableException(winsockErrorToString(err));
default:
throw XArchNetworkName(winsockErrorToString(err));
throw ArchNetworkNameException(winsockErrorToString(err));
}
}

View File

@ -7,7 +7,7 @@
#include "deskflow/win32/AppUtilWindows.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "arch/win32/ArchMiscWindows.h"
#include "arch/win32/XArchWindows.h"
#include "base/Event.h"

View File

@ -128,7 +128,7 @@ void *Thread::threadFunc(void *vjob)
LOG_DEBUG1("thread 0x%08x entry", id);
job->run();
LOG_DEBUG1("thread 0x%08x exit", id);
} catch (XThreadCancel &) {
} catch (ThreadCancelException &) {
// client called cancel()
LOG_DEBUG1("caught cancel on thread 0x%08x", id);
delete job;

View File

@ -76,7 +76,7 @@ public:
\code
catch(ThreadExit&) { throw; }
\endcode
or add the \c RETHROW_XTHREAD macro to the \c catch(...) block.
or add the \c RETHROW_THREADEXCEPTION macro to the \c catch(...) block.
*/
[[noreturn]] static void exit(void *);
@ -94,17 +94,17 @@ public:
Instead, it unwinds the stack and destroys automatic objects, as
if cancel() threw an exception (which is, in fact, what it does).
Threads must take care to unlock and clean up any resources they
may have, especially mutexes. They can \c catch(XThreadCancel) to
may have, especially mutexes. They can \c catch(ThreadCancelException) to
do that then rethrow the exception or they can let it happen
automatically by doing clean up in the d'tors of automatic
objects (like Lock). Clients are strongly encouraged to do the latter.
During cancellation, further cancel() calls are ignored (i.e.
a thread cannot be interrupted by a cancel during cancellation).
Clients that \c catch(XThreadCancel) must always rethrow the
Clients that \c catch(ThreadCancelException) must always rethrow the
exception. Clients that \c catch(...) must either rethrow the
exception or include a \c catch(XThreadCancel) handler that
rethrows. The \c RETHROW_XTHREAD macro may be useful for that.
exception or include a \c catch(ThreadCancelException) handler that
rethrows. The \c RETHROW_THREADEXCEPTION macro may be useful for that.
*/
void cancel();

View File

@ -8,15 +8,15 @@
#pragma once
#include "arch/XArch.h"
#include "arch/ArchException.h"
//! Thread exception to exit
/*!
Thrown by Thread::exit() to exit a thread. Clients of Thread
must not throw this type but must rethrow it if caught (by
ThreadExitException, XThread, or ...).
ThreadExitException, ThreadException, or ...).
*/
class ThreadExitException : public XThread
class ThreadExitException : public ThreadException
{
public:
//! \c result is the result of the thread

View File

@ -8,7 +8,7 @@
#include "net/NetworkAddress.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "net/SocketException.h"
#include <algorithm>
@ -155,13 +155,13 @@ size_t NetworkAddress::resolve(size_t index)
}
}
}
} catch (XArchNetworkNameUnknown &) {
} catch (ArchNetworkNameUnknownException &) {
throw SocketAddressException(SocketAddressException::SocketError::NotFound, m_hostname, m_port);
} catch (XArchNetworkNameNoAddress &) {
} catch (ArchNetworkNameNoAddressException &) {
throw SocketAddressException(SocketAddressException::SocketError::NoAddress, m_hostname, m_port);
} catch (XArchNetworkNameUnsupported &) {
} catch (ArchNetworkNameUnsupportedException &) {
throw SocketAddressException(SocketAddressException::SocketError::Unsupported, m_hostname, m_port);
} catch (XArchNetworkName &) {
} catch (ArchNetworkNameException &) {
throw SocketAddressException(SocketAddressException::SocketError::Unknown, m_hostname, m_port);
}

View File

@ -8,7 +8,7 @@
#include "SecureListenSocket.h"
#include "SecureSocket.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/String.h"
#include "common/Settings.h"
#include "deskflow/ArgParser.h"
@ -58,7 +58,7 @@ std::unique_ptr<IDataSocket> SecureListenSocket::accept()
secureSocket->secureAccept();
return secureSocket;
} catch (XArchNetwork &) {
} catch (ArchNetworkException &) {
if (secureSocket) {
setListeningJob();
}

View File

@ -8,7 +8,7 @@
#include "SecureSocket.h"
#include "SecureUtils.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/Log.h"
#include "base/Path.h"
#include "base/String.h"
@ -589,7 +589,7 @@ void SecureSocket::checkResult(int status, int &retry)
// underlying socket I/O reproted an error
try {
ARCH->throwErrorOnSocket(getSocket());
} catch (XArchNetwork &e) {
} catch (ArchNetworkException &e) {
LOG_ERR("%s", e.what());
}
}

View File

@ -8,7 +8,7 @@
#include "net/SocketMultiplexer.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/Log.h"
#include "base/TMethodJob.h"
#include "mt/CondVar.h"
@ -173,7 +173,7 @@ void SocketMultiplexer::removeSocket(ISocket *socket)
} else {
status = 0;
}
} catch (XArchNetwork &e) {
} catch (ArchNetworkException &e) {
LOG_WARN("error in socket multiplexer: %s", e.what());
status = 0;
}

View File

@ -8,7 +8,7 @@
#include "net/TCPListenSocket.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "io/IOException.h"
@ -30,7 +30,7 @@ TCPListenSocket::TCPListenSocket(
{
try {
m_socket = ARCH->newSocket(family, IArchNetwork::SocketType::Stream);
} catch (XArchNetwork &e) {
} catch (ArchNetworkException &e) {
throw SocketCreateException(e.what());
}
}
@ -60,9 +60,9 @@ void TCPListenSocket::bind(const NetworkAddress &addr)
this, &TCPListenSocket::serviceListening, m_socket, true, false
)
);
} catch (XArchNetworkAddressInUse &e) {
} catch (ArchNetworkAddressInUseException &e) {
throw SocketAddressInUseException(e.what());
} catch (XArchNetwork &e) {
} catch (ArchNetworkException &e) {
throw SocketBindException(e.what());
}
}
@ -77,7 +77,7 @@ void TCPListenSocket::close()
m_socketMultiplexer->removeSocket(this);
ARCH->closeSocket(m_socket);
m_socket = nullptr;
} catch (XArchNetwork &e) {
} catch (ArchNetworkException &e) {
throw SocketIOCloseException(e.what());
}
}
@ -94,7 +94,7 @@ std::unique_ptr<IDataSocket> TCPListenSocket::accept()
socket = std::make_unique<TCPSocket>(m_events, m_socketMultiplexer, ARCH->acceptSocket(m_socket, nullptr));
setListeningJob();
return socket;
} catch (XArchNetwork &) {
} catch (ArchNetworkException &) {
if (socket) {
setListeningJob();
}

View File

@ -8,7 +8,7 @@
#include "net/TCPSocket.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "mt/Lock.h"
@ -35,7 +35,7 @@ TCPSocket::TCPSocket(IEventQueue *events, SocketMultiplexer *socketMultiplexer,
{
try {
m_socket = ARCH->newSocket(family, IArchNetwork::SocketType::Stream);
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
throw SocketCreateException(e.what());
}
@ -75,9 +75,9 @@ void TCPSocket::bind(const NetworkAddress &addr)
{
try {
ARCH->bindSocket(m_socket, addr.getAddress());
} catch (const XArchNetworkAddressInUse &e) {
} catch (const ArchNetworkAddressInUseException &e) {
throw SocketAddressInUseException(e.what());
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
throw SocketBindException(e.what());
}
}
@ -103,7 +103,7 @@ void TCPSocket::close()
m_socket = nullptr;
try {
ARCH->closeSocket(socket);
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
// ignore, there's not much we can do
LOG_WARN("error closing socket: %s", e.what());
}
@ -184,7 +184,7 @@ void TCPSocket::shutdownInput()
// shutdown socket for reading
try {
ARCH->closeSocketForRead(m_socket);
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
// ignore, there's not much we can do
LOG_WARN("error closing socket: %s", e.what());
}
@ -210,7 +210,7 @@ void TCPSocket::shutdownOutput()
// shutdown socket for writing
try {
ARCH->closeSocketForWrite(m_socket);
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
// ignore, there's not much we can do
LOG_WARN("error closing socket: %s", e.what());
}
@ -265,7 +265,7 @@ void TCPSocket::connect(const NetworkAddress &addr)
// connection is in progress
m_writable = true;
}
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
throw SocketConnectException(e.what());
}
}
@ -284,11 +284,11 @@ void TCPSocket::init()
// that should be sent without (much) delay. for example, the
// mouse motion messages are much less useful if they're delayed.
ARCH->setNoDelayOnSocket(m_socket, true);
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
try {
ARCH->closeSocket(m_socket);
m_socket = nullptr;
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
// ignore, there's not much we can do
LOG_WARN("error closing socket: %s", e.what());
}
@ -469,7 +469,7 @@ ISocketMultiplexerJob *TCPSocket::serviceConnecting(ISocketMultiplexerJob *job,
try {
// connection may have failed or succeeded
ARCH->throwErrorOnSocket(m_socket);
} catch (const XArchNetwork &e) {
} catch (const ArchNetworkException &e) {
sendConnectionFailedEvent(e.what());
onDisconnected();
return newJob();
@ -503,7 +503,7 @@ ISocketMultiplexerJob *TCPSocket::serviceConnected(ISocketMultiplexerJob *job, b
if (write) {
try {
writeResult = doWrite();
} catch (XArchNetworkShutdown &) {
} catch (ArchNetworkShutdownException &) {
// remote read end of stream hungup. our output side
// has therefore shutdown.
onOutputShutdown();
@ -513,12 +513,12 @@ ISocketMultiplexerJob *TCPSocket::serviceConnected(ISocketMultiplexerJob *job, b
m_connected = false;
}
writeResult = New;
} catch (XArchNetworkDisconnected &) {
} catch (ArchNetworkDisconnectedException &) {
// stream hungup
onDisconnected();
sendEvent(SocketDisconnected);
writeResult = New;
} catch (XArchNetwork &e) {
} catch (ArchNetworkException &e) {
// other write error
LOG_WARN("error writing socket: %s", e.what());
onDisconnected();
@ -531,12 +531,12 @@ ISocketMultiplexerJob *TCPSocket::serviceConnected(ISocketMultiplexerJob *job, b
if (read && m_readable) {
try {
readResult = doRead();
} catch (XArchNetworkDisconnected &) {
} catch (ArchNetworkDisconnectedException &) {
// stream hungup
sendEvent(SocketDisconnected);
onDisconnected();
readResult = New;
} catch (XArchNetwork &e) {
} catch (ArchNetworkException &e) {
// ignore other read error
LOG_WARN("error reading socket: %s", e.what());
}

View File

@ -9,7 +9,7 @@
#include "platform/EiScreen.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/Stopwatch.h"

View File

@ -7,7 +7,7 @@
#include "platform/OSXClipboard.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/Log.h"
#include "deskflow/Clipboard.h"
#include "platform/OSXClipboardBMPConverter.h"
@ -202,7 +202,7 @@ std::string OSXClipboard::get(Format format) const
LOG_DEBUG("exception thrown in OSXClipboard::get MacError (%d)", err);
} catch (...) {
LOG_DEBUG("unknown exception in OSXClipboard::get");
RETHROW_XTHREAD
RETHROW_THREADEXCEPTION
}
if (buffer != nullptr)

View File

@ -8,7 +8,7 @@
#include "platform/OSXScreen.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/EventQueue.h"
#include "base/IEventQueue.h"
#include "base/Log.h"

View File

@ -9,7 +9,7 @@
#include "platform/XWindowsScreen.h"
#include "arch/Arch.h"
#include "arch/XArch.h"
#include "arch/ArchException.h"
#include "base/IEventQueue.h"
#include "base/Log.h"
#include "base/Stopwatch.h"

View File

@ -7,7 +7,7 @@
#include "arch/IArchNetwork.h"
#include "lib/arch/unix/ArchNetworkBSD.h"
#include "lib/arch/XArch.h"
#include "lib/arch/ArchException.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@ -69,7 +69,7 @@ TEST(ArchNetworkBSDTests, pollSocket_mockAccessError_throws)
const auto f = [&] { networkBSD.pollSocket(entries.data(), static_cast<int>(entries.size()), 1); };
EXPECT_THROW({ f(); }, XArchNetworkAccess);
EXPECT_THROW({ f(); }, ArchNetworkAccessException);
}
TEST(ArchNetworkBSDTests, pollSocket_pfdHasRevents_copiedToEntries)