fintp_log
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AppExceptions.h
Go to the documentation of this file.
1 /*
2 * FinTP - Financial Transactions Processing Application
3 * Copyright (C) 2013 Business Information Systems (Allevo) S.R.L.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 * or contact Allevo at : 031281 Bucuresti, 23C Calea Vitan, Romania,
18 * phone +40212554577, office@allevo.ro <mailto:office@allevo.ro>, www.allevo.ro.
19 */
20 
21 //AppExceptions.h
22 //contains AppException class - Holds Application Exception
23 //def enum EventType
24 #ifndef APPEXCEPTIONS_H
25 #define APPEXCEPTIONS_H
26 
27 #include "DllMainLog.h"
28 #include "Collections.h"
29 #include <string>
30 #include <iostream>
31 
32 using namespace std;
33 
34 namespace FinTP
35 {
37  {
38  public :
39  enum EventTypeEnum { Error = 1, Warning = 2, Info = 4, Management = 8};
40 
41  // .ctor
42  explicit EventType( const EventTypeEnum eventType = EventType::Error ) { m_EventType = eventType; }
43 
44  // convert to string
45  string ToString() const;
46  static string ToString( const EventTypeEnum type );
47 
48  static EventTypeEnum Parse( const string& value );
49 
50  EventTypeEnum getType() const { return m_EventType; }
51 
52  private :
54  };
55 
57  {
58  public :
59  enum EventSeverityEnum { Fatal, Transient, Info };
60 
61  // .ctor
62  explicit EventSeverity( const EventSeverityEnum severity = EventSeverity::Transient ) { m_Severity = severity; }
63  EventSeverity& operator=( const EventSeverityEnum severity )
64  {
65  m_Severity = severity;
66  return *this;
67  }
68 
69  // convert to string
70  string ToString() const;
71  static EventSeverityEnum Parse( const string& value );
72 
73  EventSeverityEnum getSeverity() const { return m_Severity; }
74 
75  private :
77  };
78 
79  class ExportedLogObject AppException : public std::exception
80  {
81  protected :
82 
83  string m_MachineName; // name of the machine generating this event
84  static string m_CrtMachineName;
85  string m_CreatedDateTime; // date/time when this message was generated
86  string m_Pid; // process id that generates this event
87 
88  EventType m_EventType; // type of event
89  EventSeverity m_EventSeverity; // severity of event
90  string m_Message; // message
91 
93  NameValueCollection* m_AdditionalInfo; // other context information
95 
96  public :
97  // .ctors & destructor
98  explicit AppException( const string& message, const EventType::EventTypeEnum eventType = EventType::Error, const NameValueCollection* additionalInfo = NULL );
99  AppException( const string& message, const std::exception& innerException, const EventType::EventTypeEnum eventType= EventType::Error, const NameValueCollection* additionalInfo = NULL );
100  AppException( const AppException & );
101  AppException(); // used by deserializer
102 
103  virtual ~AppException() throw();
104 
105  // methods
106  const char *what() const throw()
107  {
108  try
109  {
110  return m_Message.c_str();
111  } catch( ... ){};
112  return "unable to throw";
113  }
114 
115  // member accessors
116  EventType getEventType( void ) const { return m_EventType; }
117  void setEventType( const EventType::EventTypeEnum eventType ) { m_EventType = EventType( eventType ); }
118 
119  EventSeverity getSeverity( void ) const { return m_EventSeverity; }
120  void setSeverity( const EventSeverity::EventSeverityEnum eventSeverity ) { m_EventSeverity = EventSeverity( eventSeverity ); }
121 
122  string getMessage( void ) const { return m_Message; }
123  void setMessage( const string& message ) { m_Message = message; }
124 
125  string getException( void ) const { return m_InnerException; }
126  //exception* getExceptionPtr() const { return m_Exception; }
127  void setException( const std::exception& innerException );
128  void setException( const string& innerException ){ m_InnerException = innerException; }
129 
130  string getPid() const { return m_Pid; }
131  void setPid( const string& value ) { m_Pid = value; }
132 
133  string getCreatedDateTime() const { return m_CreatedDateTime; }
134  void setCreatedDateTime( const string& datetime ){ m_CreatedDateTime = datetime; }
135 
136  string getCorrelationId() const { return m_CorrelationId; }
137  void setCorrelationId( const string& correlid ){ m_CorrelationId = correlid; }
138 
139  string getMachineName() const { return m_MachineName; }
140  void setMachineName( const string& machine ){ m_MachineName = machine; }
141 
142  const NameValueCollection* getAdditionalInfo( void ) const;
143  string getAdditionalInfo( const string& name ) const { return ( *m_AdditionalInfo )[ name ]; }
144  void setAdditionalInfo( const NameValueCollection* additionalInfo );
145  void setAdditionalInfo( const string& name, const string& value );
146  void addAdditionalInfo( const string& name, const string& value );
147 
148  void InitDefaultValues();
149 
150  AppException& operator=( const AppException& ex );
151 
152  friend ostream& operator << ( ostream& os, const FinTP::AppException& except );
153 
154  protected:
155 
156  // methods
157  // set basic information about this exception.
158  void setBasicExceptionInfo( );
159  void addBasicExceptionInfo();
160  };
161 
162  ostream& operator << ( ostream& os, const FinTP::AppException& except );
163 }
164 
165 #endif // CACHEMANAGER_H