1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef ICE_EXCEPTION_H
6 #define ICE_EXCEPTION_H
7 
8 #include <IceUtil/Exception.h>
9 #include <Ice/Config.h>
10 #include <Ice/Format.h>
11 #include <Ice/Handle.h>
12 #include <Ice/ObjectF.h>
13 #include <Ice/ValueF.h>
14 #include <Ice/SlicedDataF.h>
15 
16 namespace Ice
17 {
18 
19 class OutputStream;
20 class InputStream;
21 
22 typedef IceUtil::Exception Exception;
23 
24 /**
25  * Base class for all Ice run-time exceptions.
26  * \headerfile Ice/Ice.h
27  */
28 class ICE_API LocalException : public IceUtil::Exception
29 {
30 public:
31 
32     /**
33      * The file and line number are required for all local exceptions.
34      * @param file The file name in which the exception was raised, typically __FILE__.
35      * @param line The line number at which the exception was raised, typically __LINE__.
36      */
37     LocalException(const char* file, int line);
38 
39 #ifdef ICE_CPP11_COMPILER
40     LocalException(const LocalException&) = default;
41     virtual ~LocalException();
42 #else
43     virtual ~LocalException() throw();
44 #endif
45 
46     /**
47      * Polymporphically clones this exception.
48      * @return A shallow copy of this exception.
49      */
50 #ifdef ICE_CPP11_MAPPING
51     std::unique_ptr<LocalException> ice_clone() const;
52 #else
53     virtual LocalException* ice_clone() const = 0;
54 #endif
55 
56     /**
57      * Obtains the Slice type ID of this exception.
58      * @return The fully-scoped type ID.
59      */
60     static const std::string& ice_staticId();
61 };
62 
63 /**
64  * Base class for all Ice user exceptions.
65  * \headerfile Ice/Ice.h
66  */
67 class ICE_API UserException : public IceUtil::Exception
68 {
69 public:
70 
71     /**
72      * Polymporphically clones this exception.
73      * @return A shallow copy of this exception.
74      */
75 #ifdef ICE_CPP11_MAPPING
76     std::unique_ptr<UserException> ice_clone() const;
77 #else
78     virtual UserException* ice_clone() const = 0;
79 #endif
80     virtual Ice::SlicedDataPtr ice_getSlicedData() const;
81 
82     /**
83      * Obtains the Slice type ID of this exception.
84      * @return The fully-scoped type ID.
85      */
86     static const std::string& ice_staticId();
87 
88     /// \cond STREAM
89     virtual void _write(::Ice::OutputStream*) const;
90     virtual void _read(::Ice::InputStream*);
91 
92     virtual bool _usesClasses() const;
93     /// \endcond
94 
95 protected:
96 
97     /// \cond STREAM
_writeImpl(::Ice::OutputStream *)98     virtual void _writeImpl(::Ice::OutputStream*) const {}
_readImpl(::Ice::InputStream *)99     virtual void _readImpl(::Ice::InputStream*) {}
100     /// \endcond
101 };
102 
103 /**
104  * Base class for all Ice system exceptions.
105  *
106  * System exceptions are currently Ice internal, non-documented
107  * exceptions.
108  * \headerfile Ice/Ice.h
109  */
110 class ICE_API SystemException : public IceUtil::Exception
111 {
112 public:
113 
114     /**
115      * The file and line number are required for all local exceptions.
116      * @param file The file name in which the exception was raised, typically __FILE__.
117      * @param line The line number at which the exception was raised, typically __LINE__.
118      */
119     SystemException(const char* file, int line);
120 
121 #ifdef ICE_CPP11_COMPILER
122     SystemException(const SystemException&) = default;
123     virtual ~SystemException();
124 #else
125     virtual ~SystemException() throw();
126 #endif
127 
128     /**
129      * Polymporphically clones this exception.
130      * @return A shallow copy of this exception.
131      */
132 #ifdef ICE_CPP11_MAPPING
133     std::unique_ptr<SystemException> ice_clone() const;
134 #else
135     virtual SystemException* ice_clone() const = 0;
136 #endif
137 
138     /**
139      * Obtains the Slice type ID of this exception.
140      * @return The fully-scoped type ID.
141      */
142     static const std::string& ice_staticId();
143 };
144 
145 }
146 
147 namespace IceInternal
148 {
149 
150 namespace Ex
151 {
152 
153 ICE_API void throwUOE(const ::std::string&, const ::Ice::ValuePtr&);
154 ICE_API void throwMemoryLimitException(const char*, int, size_t, size_t);
155 ICE_API void throwMarshalException(const char*, int, const std::string&);
156 
157 }
158 
159 }
160 
161 #endif
162