TreeFrogFramework: src/tfexception.h Source File

1#pragma once

3#include <QByteArray>

4#include <QString>

5#include <exception>

6

7

9public:

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 }

22 std::exception(e),

23 msg(e.msg), file(e.file), line(e.line), whatmsg(e.whatmsg) { }

25

26 QString message() const { return msg; }

27 QString fileName() const { return file; }

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

35protected:

38 int line {0};

40};

41

42

44public:

47

48 void raise() const override { throw *this; }

50 QString className() const override { return QStringLiteral("RuntimeException"); }

51};

52

53

55public:

58

59 void raise() const override { throw *this; }

61 QString className() const override { return QStringLiteral("SecurityException"); }

62};

63

64

66public:

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

77public:

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

88public:

90 TfException(QStringLiteral("HTTP status code: %1").arg(statusCode), fileName, lineNumber),

91 code(statusCode) { }

92

94

95 void raise() const override { throw *this; }

97 QString className() const override { return QStringLiteral("ClientErrorException"); }

98

99private:

100 int code;

101};

102

103

105public:

108

109 void raise() const override { throw *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

void raise() const override

Raises the exception.

Definition tfexception.h:95

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

void raise() const override

Raises the exception.

Definition tfexception.h:81

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

void raise() const override

Raises the exception.

Definition tfexception.h:48

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

void raise() const override

Raises the exception.

Definition tfexception.h:59

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

void raise() const override

Raises the exception.

Definition tfexception.h:70

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

void raise() const override

Raises the exception.

Definition tfexception.h:109

The TfException class is a base class for all TreeFrog exception classes.

Definition tfexception.h:8

virtual const char * what() const noexcept override

Definition tfexception.h:33

virtual std::exception * clone() const

Creates and returns a deep copy of the current data.

Definition tfexception.h:31

virtual void raise() const

Raises the exception.

Definition tfexception.h:30

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