2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-12-16 15:52:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 - 2026 Deskflow Developers
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2025-08-07 21:26:44 +00:00
|
|
|
#include "base/BaseException.h"
|
2014-03-21 08:32:36 +00:00
|
|
|
#include "base/String.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
#include <cstdarg>
|
|
|
|
|
|
|
|
|
|
//
|
2025-08-07 21:26:44 +00:00
|
|
|
// BaseException
|
2012-06-10 16:50:54 +00:00
|
|
|
//
|
|
|
|
|
|
2025-08-07 21:26:44 +00:00
|
|
|
BaseException::BaseException() : std::runtime_error("")
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-16 15:52:17 +00:00
|
|
|
BaseException::BaseException(const QString &msg) : std::runtime_error(msg.toStdString())
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// do nothing
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-08-07 21:26:44 +00:00
|
|
|
const char *BaseException::what() const throw()
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
if (const char *what = std::runtime_error::what(); what != nullptr && what[0] != '\0') {
|
2024-07-16 08:30:35 +00:00
|
|
|
return what;
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2024-07-16 08:30:35 +00:00
|
|
|
|
|
|
|
|
m_what = getWhat();
|
2025-12-16 15:52:17 +00:00
|
|
|
return qPrintable(m_what);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-16 15:52:17 +00:00
|
|
|
QString BaseException::format(const char * /*id*/, const char *fmt, ...) const noexcept
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
// FIXME -- lookup message string using id as an index. set
|
|
|
|
|
// fmt to that string if it exists.
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
// format
|
2025-12-16 15:52:17 +00:00
|
|
|
QString result;
|
2024-07-02 19:07:06 +00:00
|
|
|
va_list args;
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
try {
|
2025-12-16 15:52:17 +00:00
|
|
|
result = QString::fromStdString(deskflow::string::vformat(fmt, args));
|
2024-07-02 19:07:06 +00:00
|
|
|
} catch (...) {
|
|
|
|
|
// ignore
|
|
|
|
|
result.clear();
|
|
|
|
|
}
|
|
|
|
|
va_end(args);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return result;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|