KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
commonexception.h
1/**
2 * CommonException
3 *
4 * A base class for Qt exceptions
5 *
6 * Stephen Punak, September 17 2023
7 */
8#ifndef COMMONEXCEPTION_H
9#define COMMONEXCEPTION_H
10
11#include <QException>
12#include <QString>
13#include <Kanoop/kanoopcommon.h>
14
15/**
16 * @brief Base exception class for KanoopCommonQt, extending QException with a message and error code.
17 */
18class KANOOP_EXPORT CommonException : public QException
19{
20public:
21 /**
22 * @brief Construct a CommonException with a message and optional error code.
23 * @param message Human-readable description of the error
24 * @param code Optional numeric error code (default 0)
25 */
26 CommonException(const QString& message, qint32 code = 0);
27
28 /** @brief Re-throw this exception. */
29 void raise() const override { throw *this; }
30
31 /** @brief Create a heap-allocated copy of this exception.
32 * @return New CommonException allocated on the heap. */
33 CommonException *clone() const override { return new CommonException(*this); }
34
35 /**
36 * @brief Return the error message.
37 * @return Human-readable error description
38 */
39 virtual QString message() const { return _message; }
40
41 /**
42 * @brief Return the numeric error code.
43 * @return Error code supplied at construction
44 */
45 virtual qint32 code() const { return _code; }
46
47private:
48 QString _message;
49 qint32 _code;
50};
51
52#endif // COMMONEXCEPTION_H
CommonException.
CommonException * clone() const override
Create a heap-allocated copy of this exception.
CommonException(const QString &message, qint32 code=0)
Construct a CommonException with a message and optional error code.
void raise() const override
Re-throw this exception.
virtual qint32 code() const
Return the numeric error code.
virtual QString message() const
Return the error message.