deskflow/src/lib/base/BaseException.h

50 lines
1.2 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 - 2026 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
2012-06-10 16:50:54 +00:00
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include <stdexcept>
#include <string>
2012-06-10 16:50:54 +00:00
#include <QString>
2012-06-10 16:50:54 +00:00
//! Exception base class
/*!
This is the base class of most exception types.
*/
class BaseException : public std::runtime_error
{
2012-06-10 16:50:54 +00:00
public:
//! Use getWhat() as the result of what()
BaseException();
//! Use \c msg as the result of what()
explicit BaseException(const QString &msg);
~BaseException() throw() override = default;
2012-06-10 16:50:54 +00:00
//! Reason for exception
const char *what() const throw() override;
2012-06-10 16:50:54 +00:00
protected:
//! Get a human readable string describing the exception
virtual QString getWhat() const noexcept
{
return {};
}
//! Format a string
/*!
Looks up a message format using \c id, using \c defaultFormat if
no format can be found, then replaces positional parameters in
the format string and returns the result.
*/
virtual QString format(const char *id, const char *defaultFormat, ...) const noexcept;
2012-06-10 16:50:54 +00:00
private:
mutable QString m_what;
2012-06-10 16:50:54 +00:00
};