Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
89 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
#ifndef __TEXCEPT_H__
20
#define __TEXCEPT_H__
21
 
22
#include <string>
23
 
24
class TXceptBase
25
{
26
    public:
27
        TXceptBase (const std::string & message,
28
                    const std::string & categorie,
29
                    const std::string & file,
30
                    const int         & iLine,
31
                    bool bFatal = false);
32
 
33
        virtual ~TXceptBase ();
34
 
35
        const std::string & what()         const { return mMessage; }
36
        virtual std::string  getMessage()  const { return mMessage; }
37
        const std::string & getCategorie() const { return mCategory; }
38
        const std::string & getFile()      const { return mFile; }
39
        int getLine()                      const { return mLine; }
40
        bool isFatal()                     const { return mbFatal; }
41
        void setFatal(bool bFatal) { mbFatal = bFatal; }
42
        virtual void logIt (void) ;
43
 
44
    private:
45
        std::string mMessage;
46
        std::string mCategory;
47
        std::string mFile;
48
        int         mLine{0};
49
        bool        mbFatal{false};          // true: schwerer Fehler + sofortiger Abbruch, false(default): allg. Fehler
50
};
51
 
52
class TXceptNetwork : public TXceptBase
53
{
54
    public:
55
        // ctr mit Uebergabe msg
56
        TXceptNetwork (const std::string& message, const std::string& file, int iLine, bool bFatal = false);
57
        // ctr ohne Uebergabe msg
58
        TXceptNetwork (const std::string& file, int iLine, bool bFatal = false);
59
};
60
 
61
class TXceptComm : public TXceptBase
62
{
63
public:
64
    // ctr mit Uebergabe msg
65
    TXceptComm (const std::string& message, const std::string& file, int iLine, bool bFatal = false);
66
    // ctr ohne Uebergabe msg
67
    TXceptComm (const std::string& file, int iLine, bool bFatal = false);
68
};
69
 
92 andreas 70
class TXceptFatal : public TXceptBase
71
{
72
public:
73
    // ctr mit Uebergabe msg
74
    TXceptFatal (const std::string& message, const std::string& file, int iLine, bool bFatal = true);
75
    // ctr ohne Uebergabe msg
76
    TXceptFatal (const std::string& file, int iLine, bool bFatal = true);
77
};
78
 
89 andreas 79
#define XCEPTNETWORK(msg)   throw TXceptNetwork (msg, __FILE__, __LINE__, false)
80
#define EXCEPTNETWORK()     throw TXceptNetwork (__FILE__, __LINE__, false)
81
#define EXCEPTNETFATAL()    throw TXceptNetwork (__FILE__, __LINE__, true)
82
 
83
#define XCEPTCOMM(msg)      throw TXceptComm    (msg, __FILE__, __LINE__, false)
84
#define EXCEPTCOMM()        throw TXceptComm    (__FILE__, __LINE__, false)
85
#define EXCEPTCOMMFATAL()   throw TXceptComm    (__FILE__, __LINE__, true)
86
 
92 andreas 87
#define EXCEPTFATALMSG(msg) throw TXceptFatal   (msg, __FILE__, __LINE__, true)
88
#define EXCEPTFATAL()       throw TXceptFatal   (__FILE__, __LINE__, true)
89
 
89 andreas 90
#endif