446 |
andreas |
1 |
/*
|
|
|
2 |
* Copyright (C) 2022 by Andreas Theofilu <andreas@theosys.at>
|
|
|
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#include "texcept.h"
|
|
|
20 |
#include "terror.h"
|
|
|
21 |
|
|
|
22 |
#include <sstream>
|
|
|
23 |
|
|
|
24 |
using namespace std;
|
|
|
25 |
|
|
|
26 |
TXceptBase::TXceptBase(const string& message, const string& categorie, const string& file, const int& iLine, bool bFatal)
|
|
|
27 |
: mMessage(message),
|
|
|
28 |
mCategory(categorie),
|
|
|
29 |
mFile(file),
|
|
|
30 |
mLine(iLine),
|
|
|
31 |
mbFatal(bFatal)
|
|
|
32 |
{
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
TXceptBase::~TXceptBase()
|
|
|
36 |
{
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
void TXceptBase::logIt (void)
|
|
|
40 |
{
|
|
|
41 |
string sFehlertyp = "*** an EXCEPTION occured ***";
|
|
|
42 |
string sAbbruch;
|
|
|
43 |
|
|
|
44 |
if (mbFatal)
|
|
|
45 |
{
|
|
|
46 |
sFehlertyp = "*** a FATAL EXCEPTION occured ***";
|
|
|
47 |
sAbbruch = "FATAL ERROR, PROGRAM ABORT!";
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
time_t t = time(NULL);
|
|
|
51 |
struct tm *tmp;
|
|
|
52 |
tmp = localtime(&t);
|
|
|
53 |
char timeStr[200];
|
|
|
54 |
strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", tmp);
|
|
|
55 |
|
|
|
56 |
stringstream str;
|
|
|
57 |
str << sFehlertyp << std::endl
|
|
|
58 |
<< "msg : " << getMessage() << std::endl
|
|
|
59 |
<< "category : " << getCategorie() << std::endl
|
|
|
60 |
<< "time : " << timeStr << std::endl
|
|
|
61 |
<< "file : " << getFile() << std::endl
|
|
|
62 |
<< "line : " << getLine() << std::endl
|
|
|
63 |
<< sAbbruch << std::endl;
|
|
|
64 |
|
|
|
65 |
mMessage = str.str();
|
|
|
66 |
MSG_ERROR(mMessage);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
TXceptNetwork::TXceptNetwork (const std::string& message, const std::string& file, int iLine, bool bFatal)
|
|
|
70 |
: TXceptBase(message, "Network error", file, iLine, bFatal)
|
|
|
71 |
{
|
|
|
72 |
logIt();
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
TXceptNetwork::TXceptNetwork (const std::string & file, int iLine, bool bFatal)
|
|
|
76 |
: TXceptBase("", "Network error", file, iLine, bFatal)
|
|
|
77 |
{
|
|
|
78 |
logIt();
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
TXceptComm::TXceptComm (const std::string& message, const std::string& file, int iLine, bool bFatal)
|
|
|
82 |
: TXceptBase(message, "Controller communication error", file, iLine, bFatal)
|
|
|
83 |
{
|
|
|
84 |
logIt();
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
TXceptComm::TXceptComm (const std::string & file, int iLine, bool bFatal)
|
|
|
88 |
: TXceptBase("", "Controller communication error", file, iLine, bFatal)
|
|
|
89 |
{
|
|
|
90 |
logIt();
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
TXceptFatal::TXceptFatal (const std::string& message, const std::string& file, int iLine, bool bFatal)
|
|
|
94 |
: TXceptBase(message, "Fatal error", file, iLine, bFatal)
|
|
|
95 |
{
|
|
|
96 |
logIt();
|
|
|
97 |
exit(1);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
TXceptFatal::TXceptFatal (const std::string & file, int iLine, bool bFatal)
|
|
|
101 |
: TXceptBase("", "Fatal error", file, iLine, bFatal)
|
|
|
102 |
{
|
|
|
103 |
logIt();
|
|
|
104 |
exit(1);
|
|
|
105 |
}
|