Ice 3.7 C++11 API Reference
Loading...
Searching...
No Matches
Exception.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_UTIL_EXCEPTION_H
6#define ICE_UTIL_EXCEPTION_H
7
8#include <IceUtil/Config.h>
9
10#include <exception>
11#include <vector>
12
13namespace IceUtil
14{
15
21class ICE_API Exception : public std::exception
22{
23public:
24
29
35 Exception(const char* file, int line);
36
37#ifndef ICE_CPP11_COMPILER
38 virtual ~Exception() throw() = 0;
39#endif
40
47 virtual std::string ice_id() const = 0;
48
53 virtual void ice_print(std::ostream& os) const;
54
59 virtual const char* what() const ICE_NOEXCEPT;
60#ifdef ICE_CPP11_MAPPING
61
66 std::unique_ptr<Exception> ice_clone() const;
67#else
72 virtual Exception* ice_clone() const = 0;
73
74 ICE_DEPRECATED_API("ice_name() is deprecated, use ice_id() instead.")
75 std::string ice_name() const;
76#endif
77
81 virtual void ice_throw() const = 0;
82
87 const char* ice_file() const;
88
93 int ice_line() const;
94
99 std::string ice_stackTrace() const;
100
101protected:
102
103#ifdef ICE_CPP11_MAPPING
105 virtual Exception* ice_cloneImpl() const = 0;
107#endif
108
109private:
110
111 const char* _file;
112 int _line;
113 const std::vector<void*> _stackFrames;
114 mutable ::std::string _str; // Initialized lazily in what().
115};
116
117ICE_API std::ostream& operator<<(std::ostream&, const Exception&);
118
119#ifdef ICE_CPP11_MAPPING
120
126template<typename E, typename B = Exception>
127class ExceptionHelper : public B
128{
129public:
130
131 using B::B;
132
133 std::unique_ptr<E> ice_clone() const
134 {
135 return std::unique_ptr<E>(static_cast<E*>(ice_cloneImpl()));
136 }
137
138 virtual void ice_throw() const override
139 {
140 throw static_cast<const E&>(*this);
141 }
142
143protected:
144
146 virtual Exception* ice_cloneImpl() const override
147 {
148 return new E(static_cast<const E&>(*this));
149 }
151};
152
153#else // C++98 mapping
154
159template<typename E>
160class ExceptionHelper : public Exception
161{
162public:
163
164 ExceptionHelper()
165 {
166 }
167
168 ExceptionHelper(const char* file, int line) : Exception(file, line)
169 {
170 }
171
172 virtual void ice_throw() const
173 {
174 throw static_cast<const E&>(*this);
175 }
176};
177
178#endif
179
185class ICE_API NullHandleException : public ExceptionHelper<NullHandleException>
186{
187public:
188
189 NullHandleException(const char*, int);
190 virtual std::string ice_id() const;
191
192#ifndef ICE_CPP11_MAPPING
193 virtual NullHandleException* ice_clone() const;
194#endif
195};
196
203class ICE_API IllegalArgumentException : public ExceptionHelper<IllegalArgumentException>
204{
205public:
206
207 IllegalArgumentException(const char*, int);
208 IllegalArgumentException(const char*, int, const std::string&);
209
210#ifndef ICE_CPP11_COMPILER
211 virtual ~IllegalArgumentException() throw();
212#endif
213
214 virtual std::string ice_id() const;
215 virtual void ice_print(std::ostream&) const;
216
217#ifndef ICE_CPP11_MAPPING
218 virtual IllegalArgumentException* ice_clone() const;
219#endif
220
225 std::string reason() const;
226
227private:
228
229 const std::string _reason;
230};
231
236class ICE_API IllegalConversionException : public ExceptionHelper<IllegalConversionException>
237{
238public:
239
240 IllegalConversionException(const char*, int);
241 IllegalConversionException(const char*, int, const std::string&);
242
243#ifndef ICE_CPP11_COMPILER
245#endif
246
247 virtual std::string ice_id() const;
248 virtual void ice_print(std::ostream&) const;
249
250#ifndef ICE_CPP11_MAPPING
251 virtual IllegalConversionException* ice_clone() const;
252#endif
253
258 std::string reason() const;
259
260private:
261
262 const std::string _reason;
263};
264
269class ICE_API SyscallException : public ExceptionHelper<SyscallException>
270{
271public:
272
273 SyscallException(const char*, int, int);
274
275#ifndef ICE_CPP11_COMPILER
276 virtual ~SyscallException() throw();
277#endif
278
279 virtual std::string ice_id() const;
280 virtual void ice_print(std::ostream&) const;
281
282#ifndef ICE_CPP11_MAPPING
283 virtual SyscallException* ice_clone() const;
284#endif
285
290 int error() const;
291
292private:
293
294 const int _error;
295};
296
297#ifdef ICE_CPP11_MAPPING
298
299template<typename E>
301
302#else // C++98 mapping
303
309template<typename E>
311{
312public:
313
314 SyscallExceptionHelper(const char* file, int line, int errorCode) :
315 SyscallException(file, line, errorCode)
316 {
317 }
318
319 virtual void ice_throw() const
320 {
321 throw static_cast<const E&>(*this);
322 }
323};
324
325#endif
326
331class ICE_API FileLockException : public ExceptionHelper<FileLockException>
332{
333public:
334
335 FileLockException(const char*, int, int, const std::string&);
336
337#ifndef ICE_CPP11_COMPILER
338 virtual ~FileLockException() throw();
339#endif
340
341 virtual std::string ice_id() const;
342 virtual void ice_print(std::ostream&) const;
343
344#ifndef ICE_CPP11_MAPPING
345 virtual FileLockException* ice_clone() const;
346#endif
347
352 std::string path() const;
353
358 int error() const;
359
360private:
361
362 const int _error;
363 std::string _path;
364};
365
371class ICE_API OptionalNotSetException : public ExceptionHelper<OptionalNotSetException>
372{
373public:
374
375 OptionalNotSetException(const char*, int);
376 virtual std::string ice_id() const;
377
378#ifndef ICE_CPP11_MAPPING
379 virtual OptionalNotSetException* ice_clone() const;
380#endif
381};
382
383}
384
385namespace IceUtilInternal
386{
387
388enum StackTraceImpl { STNone, STDbghelp, STLibbacktrace, STLibbacktracePlus, STBacktrace };
389
390ICE_API StackTraceImpl stackTraceImpl();
391
392}
393
394#endif
#define ICE_DEPRECATED_API(msg)
Definition Config.h:217
#define ICE_API
Definition Config.h:197
#define ICE_NOEXCEPT
Definition Config.h:128
Helper template for the implementation of Ice::Exception.
Definition Exception.h:128
virtual void ice_throw() const override
Throws this exception.
Definition Exception.h:138
std::unique_ptr< E > ice_clone() const
Definition Exception.h:133
Abstract base class for all Ice exceptions.
Definition Exception.h:22
std::unique_ptr< Exception > ice_clone() const
Returns a shallow polymorphic copy of this exception.
int ice_line() const
Returns the line number where this exception was constructed.
virtual std::string ice_id() const =0
Returns the type ID of this exception.
Exception()
Constructs the exception.
virtual void ice_throw() const =0
Throws this exception.
virtual void ice_print(std::ostream &os) const
Outputs a description of this exception to a stream.
std::string ice_stackTrace() const
Returns the stack trace at the point this exception was constructed.
const char * ice_file() const
Returns the name of the file where this exception was constructed.
virtual ~Exception()=0
Exception(const char *file, int line)
Constructs the exception.
virtual const char * what() const
Returns a description of this exception.
int error() const
Returns the error number for the failed locking attempt.
virtual std::string ice_id() const
Returns the type ID of this exception.
std::string path() const
Returns the path to the file.
virtual void ice_print(std::ostream &) const
Outputs a description of this exception to a stream.
FileLockException(const char *, int, int, const std::string &)
IllegalArgumentException(const char *, int, const std::string &)
std::string reason() const
Provides the reason this exception was thrown.
virtual void ice_print(std::ostream &) const
Outputs a description of this exception to a stream.
IllegalArgumentException(const char *, int)
virtual std::string ice_id() const
Returns the type ID of this exception.
virtual std::string ice_id() const
Returns the type ID of this exception.
virtual void ice_print(std::ostream &) const
Outputs a description of this exception to a stream.
IllegalConversionException(const char *, int, const std::string &)
std::string reason() const
Provides the reason this exception was thrown.
IllegalConversionException(const char *, int)
virtual std::string ice_id() const
Returns the type ID of this exception.
NullHandleException(const char *, int)
OptionalNotSetException(const char *, int)
virtual std::string ice_id() const
Returns the type ID of this exception.
This exception indicates the failure of a system call.
Definition Exception.h:270
virtual void ice_print(std::ostream &) const
Outputs a description of this exception to a stream.
int error() const
Provides the error number returned by the system call.
SyscallException(const char *, int, int)
virtual std::string ice_id() const
Returns the type ID of this exception.
Definition Optional.h:1095
ExceptionHelper< E, SyscallException > SyscallExceptionHelper
Definition Exception.h:300
std::ostream & operator<<(std::ostream &, const Exception &)