Ocean
Exception.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_BASE_EXCEPTION_H
9 #define META_OCEAN_BASE_EXCEPTION_H
10 
11 #include "ocean/base/Base.h"
12 
13 #include <exception>
14 
15 namespace Ocean
16 {
17 
18 /**
19  * Definition of the base exception.
20  * @ingroup base
21  */
22 typedef std::exception Exception;
23 
24 /**
25  * Definition of a base exception for the entire Ocean framework.
26  * @ingroup base
27  */
28 class OCEAN_BASE_EXPORT OceanException : public Exception
29 {
30  public:
31 
32  /**
33  * Creates a new OceanException object without any message.
34  */
35  OceanException() = default;
36 
37  /**
38  * Move constructor.
39  * @param exception The exception to be moved
40  */
41  OceanException(OceanException&& exception) noexcept;
42 
43  /**
44  * Copy constructor.
45  * @param exception The exception to be copied
46  */
47  OceanException(const OceanException& exception) noexcept;
48 
49  /**
50  * Creates a new OceanException object with a message.
51  * @param message Exception message
52  */
53  explicit OceanException(const char* message);
54 
55  /**
56  * Creates a new OceanException object with a message.
57  * @param message Exception message
58  */
59  explicit OceanException(const std::string& message);
60 
61  /**
62  * Destructs an exception object.
63  */
64  ~OceanException() override;
65 
66  /**
67  * Returns the exception message.
68  * @return Exception message
69  */
70  const char* what() const noexcept override;
71 
72  /**
73  * Move operator.
74  * @param exception The exception to be moved
75  * @return Reference to this object
76  */
77  OceanException& operator=(OceanException&& exception) noexcept;
78 
79  /**
80  * Copy operator.
81  * @param exception The exception to be moved
82  * @return Reference to this object
83  */
84  OceanException& operator=(const OceanException& exception) noexcept;
85 
86  private:
87 
88  /**
89  * Sets a message.
90  * @param message The message to set, must be valid
91  */
92  void setMessage(const char* message);
93 
94  /**
95  * Releases the exception and all resources.
96  */
97  void release();
98 
99  private:
100 
101  /// Exception message.
102  char* message_ = nullptr;
103 };
104 
105 /**
106  * Definition of a base exception for not implemented code.
107  * @ingroup base
108  */
109 class OCEAN_BASE_EXPORT NotImplementedException : public OceanException
110 {
111  public:
112 
113  /**
114  * Creates a new exception for not implemented code without any message.
115  */
117 
118  /**
119  * Creates a new exception for not implemented code with a message.
120  * @param message Exception message
121  */
122  explicit NotImplementedException(const char* message);
123 
124  /**
125  * Creates a new exception for not implemented code with a message.
126  * @param message Exception message
127  */
128  explicit NotImplementedException(const std::string& message);
129 };
130 
131 /**
132  * Definition of a base exception for missing implementations.
133  * @ingroup base
134  */
135 class OCEAN_BASE_EXPORT MissingImplementationException : public OceanException
136 {
137  public:
138 
139  /**
140  * Creates a new exception for missing implementations.
141  */
143 
144  /**
145  * Creates a new exception for missing implementations.
146  * @param message Exception message
147  */
148  explicit MissingImplementationException(const char* message);
149 
150  /**
151  * Creates a new exception for missing implementations.
152  * @param message Exception message
153  */
154  explicit MissingImplementationException(const std::string& message);
155 };
156 
157 /**
158  * Definition of a base exception for not supported functionalities.
159  * @ingroup base
160  */
161 class OCEAN_BASE_EXPORT NotSupportedException : public OceanException
162 {
163  public:
164 
165  /**
166  * Creates a new exception for not supported functionalities without any message.
167  */
169 
170  /**
171  * Creates a new exception for not supported functionalities with a message.
172  * @param message Exception message
173  */
174  explicit NotSupportedException(const char* message);
175 
176  /**
177  * Creates a new exception for not supported functionalities with a message.
178  * @param message Exception message
179  */
180  explicit NotSupportedException(const std::string& message);
181 };
182 
183 /**
184  * Definition of a base exception if an out of memory problem occurs.
185  * @ingroup base
186  */
187 class OCEAN_BASE_EXPORT OutOfMemoryException : public OceanException
188 {
189  public:
190 
191  /**
192  * Creates a new exception if not enough memory is available without any message.
193  */
195 
196  /**
197  * Creates a new exception if not enough memory is available with a message.
198  * @param message Exception message
199  */
200  explicit OutOfMemoryException(const char* message);
201 
202  /**
203  * Creates a new exception if not enough memory is available with a message.
204  * @param message Exception message
205  */
206  explicit OutOfMemoryException(const std::string& message);
207 };
208 
209 }
210 
211 #endif // META_OCEAN_BASE_EXCEPTION_H
Definition of a base exception for missing implementations.
Definition: Exception.h:136
MissingImplementationException(const char *message)
Creates a new exception for missing implementations.
MissingImplementationException(const std::string &message)
Creates a new exception for missing implementations.
MissingImplementationException()
Creates a new exception for missing implementations.
Definition of a base exception for not implemented code.
Definition: Exception.h:110
NotImplementedException(const std::string &message)
Creates a new exception for not implemented code with a message.
NotImplementedException(const char *message)
Creates a new exception for not implemented code with a message.
NotImplementedException()
Creates a new exception for not implemented code without any message.
Definition of a base exception for not supported functionalities.
Definition: Exception.h:162
NotSupportedException(const std::string &message)
Creates a new exception for not supported functionalities with a message.
NotSupportedException()
Creates a new exception for not supported functionalities without any message.
NotSupportedException(const char *message)
Creates a new exception for not supported functionalities with a message.
Definition of a base exception for the entire Ocean framework.
Definition: Exception.h:29
const char * what() const noexcept override
Returns the exception message.
~OceanException() override
Destructs an exception object.
OceanException(const std::string &message)
Creates a new OceanException object with a message.
OceanException(const OceanException &exception) noexcept
Copy constructor.
OceanException()=default
Creates a new OceanException object without any message.
OceanException(OceanException &&exception) noexcept
Move constructor.
OceanException(const char *message)
Creates a new OceanException object with a message.
Definition of a base exception if an out of memory problem occurs.
Definition: Exception.h:188
OutOfMemoryException(const std::string &message)
Creates a new exception if not enough memory is available with a message.
OutOfMemoryException(const char *message)
Creates a new exception if not enough memory is available with a message.
OutOfMemoryException()
Creates a new exception if not enough memory is available without any message.
std::exception Exception
Definition of the base exception.
Definition: Exception.h:22
void release(T *object)
This functions allows to release a DirectShow object if it does exist.
Definition: DSObject.h:266
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15