OpenShot Library | libopenshot  0.2.4
Exceptions.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for all Exception classes
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #ifndef OPENSHOT_EXCEPTIONS_H
32 #define OPENSHOT_EXCEPTIONS_H
33 
34 #include <string>
35 
36 namespace openshot {
37 
38  /**
39  * @brief Base exception class with a custom message variable.
40  *
41  * A custom error message field has been added to the std::exception base class. All
42  * OpenShot exception classes inherit from this class.
43  */
44  class BaseException : public std::exception //: public exception
45  {
46  protected:
47  std::string m_message;
48  public:
49  BaseException(std::string message) : m_message(message) { }
50  virtual ~BaseException() noexcept {}
51  virtual const char* what() const noexcept {
52  // return custom message
53  return m_message.c_str();
54  }
55  };
56 
57  /// Exception when a required chunk is missing
59  {
60  public:
61  int64_t frame_number;
62  int64_t chunk_number;
63  int64_t chunk_frame;
64  /**
65  * @brief Constructor
66  *
67  * @param message A message to accompany the exception
68  * @param frame_number The frame number being processed
69  * @param chunk_number The chunk requested
70  * @param chunk_frame The chunk frame
71  */
72  ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
73  : BaseException(message), frame_number(frame_number), chunk_number(chunk_number), chunk_frame(chunk_frame) { }
74  virtual ~ChunkNotFound() noexcept {}
75  };
76 
77 
78  /// Exception when accessing a blackmagic decklink card
80  {
81  public:
82  /**
83  * @brief Constructor
84  *
85  * @param message A message to accompany the exception
86  */
87  DecklinkError(std::string message)
88  : BaseException(message) { }
89  virtual ~DecklinkError() noexcept {}
90  };
91 
92  /// Exception when decoding audio packet
94  {
95  public:
96  int64_t frame_number;
97  /**
98  * @brief Constructor
99  *
100  * @param message A message to accompany the exception
101  * @param frame_number The frame number being processed
102  */
103  ErrorDecodingAudio(std::string message, int64_t frame_number)
104  : BaseException(message), frame_number(frame_number) { }
105  virtual ~ErrorDecodingAudio() noexcept {}
106  };
107 
108  /// Exception when encoding audio packet
110  {
111  public:
112  int64_t frame_number;
113  /**
114  * @brief Constructor
115  *
116  * @param message A message to accompany the exception
117  * @param frame_number The frame number being processed
118  */
119  ErrorEncodingAudio(std::string message, int64_t frame_number)
120  : BaseException(message), frame_number(frame_number) { }
121  virtual ~ErrorEncodingAudio() noexcept {}
122  };
123 
124  /// Exception when encoding audio packet
126  {
127  public:
128  int64_t frame_number;
129  /**
130  * @brief Constructor
131  *
132  * @param message A message to accompany the exception
133  * @param frame_number The frame number being processed
134  */
135  ErrorEncodingVideo(std::string message, int64_t frame_number)
136  : BaseException(message), frame_number(frame_number) { }
137  virtual ~ErrorEncodingVideo() noexcept {}
138  };
139 
140  /// Exception when an invalid # of audio channels are detected
142  {
143  public:
144  std::string file_path;
145  /**
146  * @brief Constructor
147  *
148  * @param message A message to accompany the exception
149  * @param file_path (optional) The input file being processed
150  */
151  InvalidChannels(std::string message, std::string file_path="")
152  : BaseException(message), file_path(file_path) { }
153  virtual ~InvalidChannels() noexcept {}
154  };
155 
156  /// Exception when no valid codec is found for a file
158  {
159  public:
160  std::string file_path;
161  /**
162  * @brief Constructor
163  *
164  * @param message A message to accompany the exception
165  * @param file_path (optional) The input file being processed
166  */
167  InvalidCodec(std::string message, std::string file_path="")
168  : BaseException(message), file_path(file_path) { }
169  virtual ~InvalidCodec() noexcept {}
170  };
171 
172  /// Exception for files that can not be found or opened
173  class InvalidFile : public BaseException
174  {
175  public:
176  std::string file_path;
177  /**
178  * @brief Constructor
179  *
180  * @param message A message to accompany the exception
181  * @param file_path The input file being processed
182  */
183  InvalidFile(std::string message, std::string file_path)
184  : BaseException(message), file_path(file_path) { }
185  virtual ~InvalidFile() noexcept {}
186  };
187 
188  /// Exception when no valid format is found for a file
190  {
191  public:
192  std::string file_path;
193  /**
194  * @brief Constructor
195  *
196  * @param message A message to accompany the exception
197  * @param file_path (optional) The input file being processed
198  */
199  InvalidFormat(std::string message, std::string file_path="")
200  : BaseException(message), file_path(file_path) { }
201  virtual ~InvalidFormat() noexcept {}
202  };
203 
204  /// Exception for invalid JSON
205  class InvalidJSON : public BaseException
206  {
207  public:
208  std::string file_path;
209  /**
210  * @brief Constructor
211  *
212  * @param message A message to accompany the exception
213  * @param file_path (optional) The input file being processed
214  */
215  InvalidJSON(std::string message, std::string file_path="")
216  : BaseException(message), file_path(file_path) { }
217  virtual ~InvalidJSON() noexcept {}
218  };
219 
220  /// Exception when invalid encoding options are used
222  {
223  public:
224  std::string file_path;
225  /**
226  * @brief Constructor
227  *
228  * @param message A message to accompany the exception
229  * @param file_path (optional) The input file being processed
230  */
231  InvalidOptions(std::string message, std::string file_path="")
232  : BaseException(message), file_path(file_path) { }
233  virtual ~InvalidOptions() noexcept {}
234  };
235 
236  /// Exception when invalid sample rate is detected during encoding
238  {
239  public:
240  std::string file_path;
241  /**
242  * @brief Constructor
243  *
244  * @param message A message to accompany the exception
245  * @param file_path (optional) The input file being processed
246  */
247  InvalidSampleRate(std::string message, std::string file_path="")
248  : BaseException(message), file_path(file_path) { }
249  virtual ~InvalidSampleRate() noexcept {}
250  };
251 
252  /// Exception for missing JSON Change key
254  {
255  public:
256  std::string json;
257  /**
258  * @brief Constructor
259  *
260  * @param message A message to accompany the exception
261  * @param json The json data being processed
262  */
263  InvalidJSONKey(std::string message, std::string json)
264  : BaseException(message), json(json) { }
265  virtual ~InvalidJSONKey() noexcept {}
266  };
267 
268  /// Exception when no streams are found in the file
270  {
271  public:
272  std::string file_path;
273  /**
274  * @brief Constructor
275  *
276  * @param message A message to accompany the exception
277  * @param file_path (optional) The input file being processed
278  */
279  NoStreamsFound(std::string message, std::string file_path="")
280  : BaseException(message), file_path(file_path) { }
281  virtual ~NoStreamsFound() noexcept {}
282  };
283 
284  /// Exception for frames that are out of bounds.
286  {
287  public:
288  int64_t FrameRequested;
289  int64_t MaxFrames;
290  /**
291  * @brief Constructor
292  *
293  * @param message A message to accompany the exception
294  * @param frame_requested The out-of-bounds frame number requested
295  * @param max_frames The maximum available frame number
296  */
297  OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames)
298  : BaseException(message), FrameRequested(frame_requested), MaxFrames(max_frames) { }
299  virtual ~OutOfBoundsFrame() noexcept {}
300  };
301 
302  /// Exception for an out of bounds key-frame point.
304  {
305  public:
308  /**
309  * @brief Constructor
310  *
311  * @param message A message to accompany the exception
312  * @param point_requested The out-of-bounds point requested
313  * @param max_points The maximum available point value
314  */
315  OutOfBoundsPoint(std::string message, int point_requested, int max_points)
316  : BaseException(message), PointRequested(point_requested), MaxPoints(max_points) { }
317  virtual ~OutOfBoundsPoint() noexcept {}
318  };
319 
320  /// Exception when memory could not be allocated
321  class OutOfMemory : public BaseException
322  {
323  public:
324  std::string file_path;
325  /**
326  * @brief Constructor
327  *
328  * @param message A message to accompany the exception
329  * @param file_path (optional) The input file being processed
330  */
331  OutOfMemory(std::string message, std::string file_path="")
332  : BaseException(message), file_path(file_path) { }
333  virtual ~OutOfMemory() noexcept {}
334  };
335 
336  /// Exception when a reader is closed, and a frame is requested
338  {
339  public:
340  std::string file_path;
341  /**
342  * @brief Constructor
343  *
344  * @param message A message to accompany the exception
345  * @param file_path (optional) The input file being processed
346  */
347  ReaderClosed(std::string message, std::string file_path="")
348  : BaseException(message), file_path(file_path) { }
349  virtual ~ReaderClosed() noexcept {}
350  };
351 
352  /// Exception when resample fails
354  {
355  public:
356  std::string file_path;
357  /**
358  * @brief Constructor
359  *
360  * @param message A message to accompany the exception
361  * @param file_path (optional) The input file being processed
362  */
363  ResampleError(std::string message, std::string file_path="")
364  : BaseException(message), file_path(file_path) { }
365  virtual ~ResampleError() noexcept {}
366  };
367 
368  /// Exception when too many seek attempts happen
370  {
371  public:
372  std::string file_path;
373  /**
374  * @brief Constructor
375  *
376  * @param message A message to accompany the exception
377  * @param file_path (optional) The input file being processed
378  */
379  TooManySeeks(std::string message, std::string file_path="")
380  : BaseException(message), file_path(file_path) { }
381  virtual ~TooManySeeks() noexcept {}
382  };
383 
384  /// Exception when a writer is closed, and a frame is requested
386  {
387  public:
388  std::string file_path;
389  /**
390  * @brief Constructor
391  *
392  * @param message A message to accompany the exception
393  * @param file_path (optional) The output file being written
394  */
395  WriterClosed(std::string message, std::string file_path="")
396  : BaseException(message), file_path(file_path) { }
397  virtual ~WriterClosed() noexcept {}
398  };
399 }
400 
401 #endif
ErrorDecodingAudio(std::string message, int64_t frame_number)
Constructor.
Definition: Exceptions.h:103
TooManySeeks(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:379
InvalidFormat(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:199
OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames)
Constructor.
Definition: Exceptions.h:297
virtual ~InvalidCodec() noexcept
Definition: Exceptions.h:169
virtual ~TooManySeeks() noexcept
Definition: Exceptions.h:381
virtual const char * what() const noexcept
Definition: Exceptions.h:51
InvalidFile(std::string message, std::string file_path)
Constructor.
Definition: Exceptions.h:183
InvalidSampleRate(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:247
ErrorEncodingAudio(std::string message, int64_t frame_number)
Constructor.
Definition: Exceptions.h:119
Exception when a required chunk is missing.
Definition: Exceptions.h:58
OutOfMemory(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:331
std::string file_path
Definition: Exceptions.h:340
Exception when an invalid # of audio channels are detected.
Definition: Exceptions.h:141
Base exception class with a custom message variable.
Definition: Exceptions.h:44
Exception when encoding audio packet.
Definition: Exceptions.h:109
virtual ~InvalidFile() noexcept
Definition: Exceptions.h:185
virtual ~ResampleError() noexcept
Definition: Exceptions.h:365
ReaderClosed(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:347
virtual ~OutOfBoundsPoint() noexcept
Definition: Exceptions.h:317
InvalidJSONKey(std::string message, std::string json)
Constructor.
Definition: Exceptions.h:263
virtual ~ErrorEncodingVideo() noexcept
Definition: Exceptions.h:137
Exception when a reader is closed, and a frame is requested.
Definition: Exceptions.h:337
ErrorEncodingVideo(std::string message, int64_t frame_number)
Constructor.
Definition: Exceptions.h:135
Exception when encoding audio packet.
Definition: Exceptions.h:125
Exception when invalid sample rate is detected during encoding.
Definition: Exceptions.h:237
std::string file_path
Definition: Exceptions.h:388
Exception for missing JSON Change key.
Definition: Exceptions.h:253
virtual ~InvalidJSONKey() noexcept
Definition: Exceptions.h:265
std::string file_path
Definition: Exceptions.h:176
virtual ~InvalidSampleRate() noexcept
Definition: Exceptions.h:249
InvalidCodec(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:167
ResampleError(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:363
Exception when no valid codec is found for a file.
Definition: Exceptions.h:157
Exception when memory could not be allocated.
Definition: Exceptions.h:321
Exception when invalid encoding options are used.
Definition: Exceptions.h:221
std::string file_path
Definition: Exceptions.h:324
Exception when accessing a blackmagic decklink card.
Definition: Exceptions.h:79
Exception when no streams are found in the file.
Definition: Exceptions.h:269
WriterClosed(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:395
virtual ~InvalidOptions() noexcept
Definition: Exceptions.h:233
Exception for files that can not be found or opened.
Definition: Exceptions.h:173
virtual ~OutOfBoundsFrame() noexcept
Definition: Exceptions.h:299
std::string file_path
Definition: Exceptions.h:372
virtual ~ChunkNotFound() noexcept
Definition: Exceptions.h:74
InvalidJSON(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:215
virtual ~InvalidJSON() noexcept
Definition: Exceptions.h:217
std::string file_path
Definition: Exceptions.h:208
virtual ~InvalidChannels() noexcept
Definition: Exceptions.h:153
NoStreamsFound(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:279
Exception for frames that are out of bounds.
Definition: Exceptions.h:285
DecklinkError(std::string message)
Constructor.
Definition: Exceptions.h:87
virtual ~WriterClosed() noexcept
Definition: Exceptions.h:397
std::string m_message
Definition: Exceptions.h:47
std::string file_path
Definition: Exceptions.h:160
This namespace is the default namespace for all code in the openshot library.
virtual ~OutOfMemory() noexcept
Definition: Exceptions.h:333
virtual ~BaseException() noexcept
Definition: Exceptions.h:50
Exception for invalid JSON.
Definition: Exceptions.h:205
InvalidChannels(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:151
Exception for an out of bounds key-frame point.
Definition: Exceptions.h:303
virtual ~ErrorEncodingAudio() noexcept
Definition: Exceptions.h:121
virtual ~DecklinkError() noexcept
Definition: Exceptions.h:89
virtual ~InvalidFormat() noexcept
Definition: Exceptions.h:201
Exception when decoding audio packet.
Definition: Exceptions.h:93
ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
Constructor.
Definition: Exceptions.h:72
Exception when a writer is closed, and a frame is requested.
Definition: Exceptions.h:385
BaseException(std::string message)
Definition: Exceptions.h:49
InvalidOptions(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:231
Exception when no valid format is found for a file.
Definition: Exceptions.h:189
Exception when resample fails.
Definition: Exceptions.h:353
virtual ~NoStreamsFound() noexcept
Definition: Exceptions.h:281
virtual ~ReaderClosed() noexcept
Definition: Exceptions.h:349
OutOfBoundsPoint(std::string message, int point_requested, int max_points)
Constructor.
Definition: Exceptions.h:315
Exception when too many seek attempts happen.
Definition: Exceptions.h:369
virtual ~ErrorDecodingAudio() noexcept
Definition: Exceptions.h:105