libUTL++
Exception.h
1 #pragma once
2 
4 
5 #include <libutl/Object.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
18 void errToEx(const utl::Object* object = nullptr);
19 
21 
27 void h_errToEx(const utl::Object* object = nullptr);
28 
30 
31 class String;
32 
34 
41 #define UTL_EXCEPTION_DECL(exName, baseExName) \
42  class exName : public baseExName \
43  { \
44  UTL_CLASS_DECL(exName, baseExName); \
45  \
46  public: \
47  exName(utl::Object* object); \
48  \
49  exName(const utl::Object& object); \
50  \
51  exName(const char* name, utl::Object* object) \
52  : baseExName(name, object) \
53  { \
54  } \
55  \
56  exName(const char* name, const utl::Object& object) \
57  : baseExName(name, object) \
58  { \
59  } \
60  \
61  private: \
62  void init(); \
63  void \
64  deInit() \
65  { \
66  } \
67  };
68 
70 
79 #define UTL_EXCEPTION_IMPL(exNS, exName, baseExName, name) \
80  UTL_CLASS_IMPL(exNS::exName); \
81  exNS::exName::exName(utl::Object* object) \
82  : baseExName(name, object) \
83  { \
84  } \
85  \
86  exNS::exName::exName(const utl::Object& object) \
87  : baseExName(name, object) \
88  { \
89  } \
90  \
91  void exNS::exName::init() \
92  { \
93  setName(name); \
94  }
95 
97 // Exception ///////////////////////////////////////////////////////////////////////////////////////
99 
107 
109 class Exception : public Object
110 {
112 
113 public:
119  Exception(const char* name, Object* object);
120 
126  Exception(const char* name, const Object& object);
127 
131  virtual void copy(const Object& rhs);
132 
136  virtual void dump(Stream& os) const;
137 
139  const String&
140  name() const
141  {
142  ASSERTD(_name != nullptr);
143  return *_name;
144  }
145 
147  const String*
148  namePtr() const
149  {
150  return _name;
151  }
152 
154  void setName(const char* name);
155 
157  Object*
158  object() const
159  {
160  return _object;
161  }
162 
164  Object*
166  {
167  Object* obj = _object;
168  _object = nullptr;
169  return obj;
170  }
171 
173  void setObject(Object* object);
174 
176  void setObject(const Object& object);
177 
178 private:
179  void init();
180  void deInit();
181 
182 private:
183  const String* _name;
184  Object* _object;
185 };
186 
188 // Host OS Exceptions //////////////////////////////////////////////////////////////////////////////
190 
197 
203 
209 
215 
221 
227 
233 
239 
241 // Stream Exceptions ///////////////////////////////////////////////////////////////////////////////
243 
249 
255 
261 
267 
269 // Network Exceptions //////////////////////////////////////////////////////////////////////////////
271 
277 
283 
289 
295 
301 
307 
313 
319 
325 
327 // Misc Exceptions /////////////////////////////////////////////////////////////////////////////////
329 
335 
341 
343 
344 UTL_NS_END;
Object * object() const
Get the associated object.
Definition: Exception.h:158
void deInit()
De-initialize UTL++.
Host has no address exception
Definition: Exception.h:318
Address in use exception
Definition: Exception.h:288
Unknown host OS exception
Definition: Exception.h:238
Network unreachable exception
Definition: Exception.h:300
Access denied exception
Definition: Exception.h:202
Invalid address/descriptor exception
Definition: Exception.h:226
File already exists exception
Definition: Exception.h:208
File not found exception
Definition: Exception.h:214
Character string.
Definition: String.h:31
#define UTL_EXCEPTION_DECL(exName, baseExName)
Declare a simple exception type.
Definition: Exception.h:41
Interrupted system call exception
Definition: Exception.h:220
Host lookup failure exception
Definition: Exception.h:312
Address not available exception
Definition: Exception.h:294
Root of UTL++ exception class hierarchy.
Definition: Exception.h:109
Non-directory component exception
Definition: Exception.h:232
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
Stream serialization exception
Definition: Exception.h:266
Stream EOF exception
Definition: Exception.h:254
const String & name() const
Get the name.
Definition: Exception.h:140
const String * namePtr() const
Get name pointer.
Definition: Exception.h:148
void errToEx(const utl::Object *object=nullptr)
Convert libc&#39;s errno to an exception.
Unknown exception.
Definition: Exception.h:340
#define UTL_CLASS_DECL_ABC(DC, BC)
Declaration of standard UTL++ functionality for an abstract base class (ABC).
Definition: macros.h:650
Stream exception (abstract)
Definition: Exception.h:248
Illegal value exception.
Definition: Exception.h:334
Connection reset by peer exception
Definition: Exception.h:306
Host not found exception
Definition: Exception.h:324
Network exception (abstract)
Definition: Exception.h:276
Stream I/O abstraction.
Definition: Stream.h:68
Connection refused exception
Definition: Exception.h:282
Host OS exception (abstract)
Definition: Exception.h:196
Stream I/O error exception
Definition: Exception.h:260
Object * takeObject()
Take the associated object.
Definition: Exception.h:165
void h_errToEx(const utl::Object *object=nullptr)
Convert libc&#39;s h_errno to an exception.
Root of UTL++ class hierarchy.
Definition: Object.h:52
void dump(const FwdIt &begin, const FwdIt &end, Stream &os, uint_t level=uint_t_max, bool key=false, bool printClassName=false, uint_t indent=0, const char *separator=nullptr)
Dump objects to the given stream (with Object::dump()).
void init()
Initialize UTL++.
#define ASSERTD
Do an assertion in DEBUG mode only.