TreeFrogFramework  2.8
tfexception.h
Go to the documentation of this file.
1 #pragma once
2 #include "tdeclexport.h"
3 #include <QByteArray>
4 #include <QString>
5 #include <exception>
6 
7 
8 class T_CORE_EXPORT TfException : public std::exception {
9 public:
10  TfException(const QString &message, const char *fileName = "", int lineNumber = 0) noexcept :
11  msg(message),
12  file(fileName), line(lineNumber)
13  {
14  whatmsg = message.toLocal8Bit();
15  if (lineNumber > 0) {
16  whatmsg += " [";
17  whatmsg += fileName;
18  whatmsg += ":" + QByteArray::number(lineNumber) + "]";
19  }
20  }
21  TfException(const TfException &e) noexcept :
22  std::exception(e),
23  msg(e.msg), file(e.file), line(e.line), whatmsg(e.whatmsg) { }
24  virtual ~TfException() throw() { }
25 
26  QString message() const { return msg; }
27  QString fileName() const { return file; }
28  int lineNumber() const { return line; }
29 
30  virtual void raise() const { throw *this; }
31  virtual std::exception *clone() const { return new TfException(*this); }
32  virtual QString className() const { return QStringLiteral("TfException"); }
33  virtual const char *what() const noexcept override { return whatmsg.constData(); }
34 
35 protected:
36  QString msg;
37  QString file;
38  int line {0};
39  QByteArray whatmsg;
40 };
41 
42 
44 public:
45  RuntimeException(const QString &message, const char *fileName = "", int lineNumber = 0) :
46  TfException(message, fileName, lineNumber) { }
47 
48  void raise() const override { throw *this; }
49  std::exception *clone() const override { return new RuntimeException(*this); }
50  QString className() const override { return QStringLiteral("RuntimeException"); }
51 };
52 
53 
55 public:
56  SecurityException(const QString &message, const char *fileName = "", int lineNumber = 0) :
57  TfException(message, fileName, lineNumber) { }
58 
59  void raise() const override { throw *this; }
60  std::exception *clone() const override { return new SecurityException(*this); }
61  QString className() const override { return QStringLiteral("SecurityException"); }
62 };
63 
64 
66 public:
67  SqlException(const QString &message, const char *fileName = "", int lineNumber = 0) :
68  TfException(message, fileName, lineNumber) { }
69 
70  void raise() const override { throw *this; }
71  std::exception *clone() const override { return new SqlException(*this); }
72  QString className() const override { return QStringLiteral("SqlException"); }
73 };
74 
75 
77 public:
78  KvsException(const QString &message, const char *fileName = "", int lineNumber = 0) :
79  TfException(message, fileName, lineNumber) { }
80 
81  void raise() const override { throw *this; }
82  std::exception *clone() const override { return new KvsException(*this); }
83  QString className() const override { return QStringLiteral("KvsException"); }
84 };
85 
86 
88 public:
89  ClientErrorException(int statusCode, const char *fileName = "", int lineNumber = 0) :
90  TfException(QStringLiteral("HTTP status code: %1").arg(statusCode), fileName, lineNumber),
91  code(statusCode) { }
92 
93  int statusCode() const { return code; }
94 
95  void raise() const override { throw *this; }
96  std::exception *clone() const override { return new ClientErrorException(*this); }
97  QString className() const override { return QStringLiteral("ClientErrorException"); }
98 
99 private:
100  int code;
101 };
102 
103 
105 public:
106  StandardException(const QString &message, const char *fileName = "", int lineNumber = 0) :
107  TfException(message, fileName, lineNumber) { }
108 
109  void raise() const override { throw *this; }
110  std::exception *clone() const override { return new StandardException(*this); }
111  QString className() const override { return QStringLiteral("StandardException"); }
112 };
113 
The ClientErrorException class represents an exception that can be thrown when communication error wi...
Definition: tfexception.h:87
std::exception * clone() const override
Creates and returns a deep copy of the current data.
Definition: tfexception.h:96
QString className() const override
Returns exception class name.
Definition: tfexception.h:97
int statusCode() const
Returns the status code.
Definition: tfexception.h:93
ClientErrorException(int statusCode, const char *fileName="", int lineNumber=0)
Copy constructor.
Definition: tfexception.h:89
The KvsException class represents an exception that can be thrown when KVS database error occurs.
Definition: tfexception.h:76
std::exception * clone() const override
Creates and returns a deep copy of the current data.
Definition: tfexception.h:82
KvsException(const QString &message, const char *fileName="", int lineNumber=0)
Copy constructor.
Definition: tfexception.h:78
QString className() const override
Returns exception class name.
Definition: tfexception.h:83
The RuntimeException class represents an exception that can be thrown when runtime error occurs.
Definition: tfexception.h:43
std::exception * clone() const override
Creates and returns a deep copy of the current data.
Definition: tfexception.h:49
QString className() const override
Returns exception class name.
Definition: tfexception.h:50
RuntimeException(const QString &message, const char *fileName="", int lineNumber=0)
Copy constructor.
Definition: tfexception.h:45
The SecurityException class represents an exception that can be thrown when a security issue is detec...
Definition: tfexception.h:54
std::exception * clone() const override
Creates and returns a deep copy of the current data.
Definition: tfexception.h:60
SecurityException(const QString &message, const char *fileName="", int lineNumber=0)
Copy constructor.
Definition: tfexception.h:56
QString className() const override
Returns exception class name.
Definition: tfexception.h:61
The SqlException class represents an exception that can be thrown when SQL database error occurs.
Definition: tfexception.h:65
std::exception * clone() const override
Creates and returns a deep copy of the current data.
Definition: tfexception.h:71
SqlException(const QString &message, const char *fileName="", int lineNumber=0)
Copy constructor.
Definition: tfexception.h:67
QString className() const override
Returns exception class name.
Definition: tfexception.h:72
The StandardException class represents an exception that can be thrown when standard error occurs in ...
Definition: tfexception.h:104
StandardException(const QString &message, const char *fileName="", int lineNumber=0)
Copy constructor.
Definition: tfexception.h:106
std::exception * clone() const override
Creates and returns a deep copy of the current data.
Definition: tfexception.h:110
QString className() const override
Returns exception class name.
Definition: tfexception.h:111
The TfException class is a base class for all TreeFrog exception classes.
Definition: tfexception.h:8
virtual std::exception * clone() const
Creates and returns a deep copy of the current data.
Definition: tfexception.h:31
virtual const char * what() const noexcept override
Definition: tfexception.h:33
int lineNumber() const
Return the line number.
Definition: tfexception.h:28
QString message() const
Returns the message.
Definition: tfexception.h:26
TfException(const QString &message, const char *fileName="", int lineNumber=0) noexcept
Constructor.
Definition: tfexception.h:10
QByteArray whatmsg
Definition: tfexception.h:39
TfException(const TfException &e) noexcept
Copy constructor.
Definition: tfexception.h:21
QString msg
Definition: tfexception.h:36
virtual QString className() const
Returns exception class name.
Definition: tfexception.h:32
QString fileName() const
Returns the file name.
Definition: tfexception.h:27
virtual ~TfException()
Destructor.
Definition: tfexception.h:24
QString file
Definition: tfexception.h:37
#define T_CORE_EXPORT
Definition: tdeclexport.h:28