~vbursian/research-assistant/intervers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
////////////////////////////////////////////////////////////////////////////////
/*! @file Excepts.h   Basic classes for specific exception handling.
- Part of RANet - Research Assistant Net Library.
- Copyright(C) 1994-2017, Viktor E. Bursian, St.Petersburg, Russia.
                          VBursian@gmail.com
*///////////////////////////////////////////////////////////////////////////////
#ifndef Excepts_H
#define Excepts_H
#include "General.h"
#include "Strings.h"
#include <exception>
namespace RA {
//------------------------------------------------------------------------------

ANNOUNCE_CLASS(xException)
ANNOUNCE_CLASS(xProgramError)
ANNOUNCE_CLASS(xAssertFailed)
ANNOUNCE_CLASS(xNotImplemented)
//ANNOUNCE_CLASS(xStreamError)


#define THROW( exception_class , message_text )  \
throw exception_class ( message_text , __FILE__ , __LINE__ , #exception_class )


#define ASSERT( expr )  \
if( !( bool( expr ) ) ) throw xAssertFailed( #expr , __FILE__ , __LINE__ )


#define ABORT_IF_NOT( expr )                                                  \
if( !( bool( expr ) ) ){                                                      \
  std::cerr << "***********************************************\n"            \
            << "*** ABORTED BECAUSE THE FOLLOWING IS FALSE:\n"                \
            << "*** " << #expr << "\n"                                        \
            << "*** FILE: " << __FILE__ << "   LINE: " << __LINE__ << "\n"    \
            << "***********************************************\n";           \
  std::terminate();                                                           \
};


//--------------------------------------------------------------- xException ---

class RANet_EXPORT  xException : public std::exception
{
  public://static
    static void               Report2cerr (const std::exception &);
  public:
    virtual                   ~xException ()
                                {}

//                              xException (rcxException  other);

                              xException (rcsString  msg_text
                                         ,rcsString  src_file_name = sString()
                                         ,int        line_no = 0
                                         ,rcsString  class_name
                                                       = sString("xException")
                                         )
                                  :TheFileName(src_file_name)
                                  ,TheLineNo(line_no)
                                  ,TheClassName(class_name)
                                  ,TheMsgText(msg_text)
                                {}

                              xException ()
                                  :TheLineNo(0)
                                  ,TheClassName("xException")
                                {}

    virtual const char *      what () const noexcept override
                                { return (const char *)TheMsgText; }

    virtual sString           MsgText () const
                                { return TheMsgText; }
    virtual sString           WhereText () const;
    virtual sString           SorryText () const;
    virtual void              Report2cerr () const;

  private: // fields
    sString                   TheFileName;
    int                       TheLineNo;
    sString                   TheClassName;
    sString                   TheMsgText;
};

//------------------------------------------------------------------------------

class RANet_EXPORT  xProgramError : public xException
{
  public:
                              xProgramError
                                  (rcsString  msg_text
                                  ,rcsString  src_file_name
//                                                         = sString()
                                  ,int        line_no
//                                                         = 0
                                  ,rcsString  class_name
                                                     = sString("xProgramError")
                                  )
                                  :xException(msg_text,src_file_name,line_no
                                             ,class_name)
                                {}
};

//------------------------------------------------------------------------------

class RANet_EXPORT  xAssertFailed : public xProgramError
{
  public:
                              xAssertFailed (literal  assertion
                                            ,literal  src_file_name
                                            ,int      line_no      );
};

//------------------------------------------------------------------------------

class RANet_EXPORT  xNotImplemented : public xProgramError
{
  public:
                              xNotImplemented (rcsString  what);
};

//------------------------------------------------------------------------------

//class RANet_EXPORT  xStreamError : public xException
//{
//  public:
//    enum                      eStreamError
//                                {Other};
//                              xStreamError ()
//                                  :Code(Other)
//                                {}
//                              xStreamError (eStreamError ACode)
//                                  :Code(ACode)
//                                {}
//    int                       Code;
//};

//------------------------------------------------------------------------------
} //namespace RA
#endif