deskflow/src/lib/base/XBase.h

47 lines
1.1 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* 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
//! Exception base class
/*!
This is the base class of most exception types.
*/
class XBase : public std::runtime_error
{
2012-06-10 16:50:54 +00:00
public:
//! Use getWhat() as the result of what()
XBase();
//! Use \c msg as the result of what()
2025-05-21 01:09:55 +00:00
explicit XBase(const std::string &msg);
~XBase() 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 std::string 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 std::string format(const char *id, const char *defaultFormat, ...) const noexcept;
2012-06-10 16:50:54 +00:00
private:
mutable std::string m_what;
2012-06-10 16:50:54 +00:00
};