OpenShot Library | libopenshot  0.3.2
Exceptions.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_EXCEPTIONS_H
14 #define OPENSHOT_EXCEPTIONS_H
15 
16 #include <string>
17 #include <cstring>
18 
19 namespace openshot {
20 
27  class ExceptionBase : public std::exception
28  {
29  protected:
30  std::string m_message;
31  public:
32  ExceptionBase(std::string message) : m_message(message) { }
33  virtual ~ExceptionBase() noexcept {}
34  virtual const char* what() const noexcept {
35  // return custom message
36  return m_message.c_str();
37  }
38  virtual std::string py_message() const {
39  // return complete message for Python exception handling
40  return m_message;
41  }
42  };
43 
45  {
46  public:
47  int64_t frame_number;
48  FrameExceptionBase(std::string message, int64_t frame_number=-1)
49  : ExceptionBase(message), frame_number(frame_number) { }
50  virtual std::string py_message() const override {
51  // return complete message for Python exception handling
52  std::string out_msg(m_message +
53  (frame_number > 0
54  ? " at frame " + std::to_string(frame_number)
55  : ""));
56  return out_msg;
57  }
58  };
59 
60 
62  {
63  public:
64  std::string file_path;
65  FileExceptionBase(std::string message, std::string file_path="")
66  : ExceptionBase(message), file_path(file_path) { }
67  virtual std::string py_message() const override {
68  // return complete message for Python exception handling
69  std::string out_msg(m_message +
70  (file_path != ""
71  ? " for file " + file_path
72  : ""));
73  return out_msg;
74  }
75  };
76 
79  {
80  public:
81  int64_t chunk_number;
82  int64_t chunk_frame;
91  ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
93  virtual ~ChunkNotFound() noexcept {}
94  };
95 
96 
99  {
100  public:
106  DecklinkError(std::string message)
107  : ExceptionBase(message) { }
108  virtual ~DecklinkError() noexcept {}
109  };
110 
113  {
114  public:
121  ErrorDecodingAudio(std::string message, int64_t frame_number=-1)
122  : FrameExceptionBase(message, frame_number) { }
123  virtual ~ErrorDecodingAudio() noexcept {}
124  };
125 
128  {
129  public:
136  ErrorEncodingAudio(std::string message, int64_t frame_number=-1)
137  : FrameExceptionBase(message, frame_number) { }
138  virtual ~ErrorEncodingAudio() noexcept {}
139  };
140 
143  {
144  public:
151  ErrorEncodingVideo(std::string message, int64_t frame_number=-1)
152  : FrameExceptionBase(message, frame_number) { }
153  virtual ~ErrorEncodingVideo() noexcept {}
154  };
155 
158  {
159  public:
166  InvalidChannels(std::string message, std::string file_path="")
167  : FileExceptionBase(message, file_path) { }
168  virtual ~InvalidChannels() noexcept {}
169  };
170 
173  {
174  public:
181  InvalidCodec(std::string message, std::string file_path="")
182  : FileExceptionBase(message, file_path) { }
183  virtual ~InvalidCodec() noexcept {}
184  };
185 
188  {
189  public:
196  InvalidFile(std::string message, std::string file_path)
197  : FileExceptionBase(message, file_path) { }
198  virtual ~InvalidFile() noexcept {}
199  };
200 
203  {
204  public:
211  InvalidFormat(std::string message, std::string file_path="")
212  : FileExceptionBase(message, file_path) { }
213  virtual ~InvalidFormat() noexcept {}
214  };
215 
218  {
219  public:
226  InvalidJSON(std::string message, std::string file_path="")
227  : FileExceptionBase(message, file_path) { }
228  virtual ~InvalidJSON() noexcept {}
229  };
230 
233  {
234  public:
241  InvalidOptions(std::string message, std::string file_path="")
242  : FileExceptionBase(message, file_path) { }
243  virtual ~InvalidOptions() noexcept {}
244  };
245 
248  {
249  public:
256  InvalidSampleRate(std::string message, std::string file_path="")
257  : FileExceptionBase(message, file_path) { }
258  virtual ~InvalidSampleRate() noexcept {}
259  };
260 
263  {
264  public:
265  std::string json;
272  InvalidJSONKey(std::string message, std::string json)
273  : ExceptionBase(message), json(json) { }
274  virtual ~InvalidJSONKey() noexcept {}
275  std::string py_message() const override {
276  std::string out_msg = m_message +
277  " for JSON data " +
278  (json.size() > 100 ? " (abbreviated): " : ": ")
279  + json.substr(0, 99);
280  return out_msg;
281  }
282  };
283 
286  {
287  public:
294  NoStreamsFound(std::string message, std::string file_path="")
295  : FileExceptionBase(message, file_path) { }
296  virtual ~NoStreamsFound() noexcept {}
297  };
298 
301  {
302  public:
303  int64_t FrameRequested;
304  int64_t MaxFrames;
312  OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames)
313  : ExceptionBase(message), FrameRequested(frame_requested), MaxFrames(max_frames) { }
314  virtual ~OutOfBoundsFrame() noexcept {}
315  std::string py_message() const override {
316  std::string out_msg(m_message
317  + " Frame requested: " + std::to_string(FrameRequested)
318  + " Max frames: " + std::to_string(MaxFrames));
319  return out_msg;
320  }
321  };
322 
325  {
326  public:
336  OutOfBoundsPoint(std::string message, int point_requested, int max_points)
337  : ExceptionBase(message), PointRequested(point_requested), MaxPoints(max_points) { }
338  virtual ~OutOfBoundsPoint() noexcept {}
339  std::string py_message() const override {
340  std::string out_msg(m_message
341  + " Point requested: " + std::to_string(PointRequested)
342  + " Max point: " + std::to_string(MaxPoints));
343  return out_msg;
344  }
345  };
346 
349  {
350  public:
357  OutOfMemory(std::string message, std::string file_path="")
358  : FileExceptionBase(message, file_path) { }
359  virtual ~OutOfMemory() noexcept {}
360  };
361 
364  {
365  public:
372  ReaderClosed(std::string message, std::string file_path="")
373  : FileExceptionBase(message, file_path) { }
374  virtual ~ReaderClosed() noexcept {}
375  };
376 
379  {
380  public:
387  ResampleError(std::string message, std::string file_path="")
388  : FileExceptionBase(message, file_path) { }
389  virtual ~ResampleError() noexcept {}
390  };
391 
392 #define TMS_DEP_MSG "The library no longer throws this exception. It will be removed in a future release."
393 
394 #ifndef SWIG
395  class
397  [[deprecated(TMS_DEP_MSG)]]
398  TooManySeeks : public FileExceptionBase
399  {
400  public:
407  [[deprecated(TMS_DEP_MSG)]]
408  TooManySeeks(std::string message, std::string file_path="")
409  : FileExceptionBase(message, file_path) { }
410  virtual ~TooManySeeks() noexcept {}
411  };
412 #endif
413 
416  {
417  public:
424  WriterClosed(std::string message, std::string file_path="")
425  : FileExceptionBase(message, file_path) { }
426  virtual ~WriterClosed() noexcept {}
427  };
428 }
429 
430 #endif
openshot::InvalidOptions::InvalidOptions
InvalidOptions(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:241
openshot::InvalidFormat
Exception when no valid format is found for a file.
Definition: Exceptions.h:202
openshot::ReaderClosed::~ReaderClosed
virtual ~ReaderClosed() noexcept
Definition: Exceptions.h:374
openshot::InvalidSampleRate
Exception when invalid sample rate is detected during encoding.
Definition: Exceptions.h:247
openshot::InvalidCodec
Exception when no valid codec is found for a file.
Definition: Exceptions.h:172
openshot::WriterClosed
Exception when a writer is closed, and a frame is requested.
Definition: Exceptions.h:415
openshot::FileExceptionBase::file_path
std::string file_path
Definition: Exceptions.h:64
openshot::InvalidCodec::InvalidCodec
InvalidCodec(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:181
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::FileExceptionBase
Definition: Exceptions.h:61
openshot::NoStreamsFound::~NoStreamsFound
virtual ~NoStreamsFound() noexcept
Definition: Exceptions.h:296
openshot::OutOfBoundsFrame::~OutOfBoundsFrame
virtual ~OutOfBoundsFrame() noexcept
Definition: Exceptions.h:314
openshot::InvalidJSONKey::~InvalidJSONKey
virtual ~InvalidJSONKey() noexcept
Definition: Exceptions.h:274
openshot::InvalidChannels::InvalidChannels
InvalidChannels(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:166
openshot::ChunkNotFound::~ChunkNotFound
virtual ~ChunkNotFound() noexcept
Definition: Exceptions.h:93
openshot::DecklinkError::~DecklinkError
virtual ~DecklinkError() noexcept
Definition: Exceptions.h:108
openshot::ResampleError::ResampleError
ResampleError(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:387
openshot::InvalidJSONKey::InvalidJSONKey
InvalidJSONKey(std::string message, std::string json)
Constructor.
Definition: Exceptions.h:272
openshot::ErrorEncodingAudio::ErrorEncodingAudio
ErrorEncodingAudio(std::string message, int64_t frame_number=-1)
Constructor.
Definition: Exceptions.h:136
openshot::OutOfBoundsFrame
Exception for frames that are out of bounds.
Definition: Exceptions.h:300
openshot::ErrorEncodingAudio
Exception when encoding audio packet.
Definition: Exceptions.h:127
openshot::ReaderClosed::ReaderClosed
ReaderClosed(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:372
openshot::ErrorEncodingAudio::~ErrorEncodingAudio
virtual ~ErrorEncodingAudio() noexcept
Definition: Exceptions.h:138
openshot::OutOfMemory::~OutOfMemory
virtual ~OutOfMemory() noexcept
Definition: Exceptions.h:359
openshot::WriterClosed::~WriterClosed
virtual ~WriterClosed() noexcept
Definition: Exceptions.h:426
openshot::FrameExceptionBase::py_message
virtual std::string py_message() const override
Definition: Exceptions.h:50
openshot::DecklinkError
Exception when accessing a blackmagic decklink card.
Definition: Exceptions.h:98
openshot::FrameExceptionBase::frame_number
int64_t frame_number
Definition: Exceptions.h:47
openshot::OutOfBoundsPoint
Exception for an out of bounds key-frame point.
Definition: Exceptions.h:324
openshot::ChunkNotFound::chunk_number
int64_t chunk_number
Definition: Exceptions.h:81
openshot::ChunkNotFound
Exception when a required chunk is missing.
Definition: Exceptions.h:78
openshot::DecklinkError::DecklinkError
DecklinkError(std::string message)
Constructor.
Definition: Exceptions.h:106
openshot::OutOfBoundsFrame::MaxFrames
int64_t MaxFrames
Definition: Exceptions.h:304
openshot::NoStreamsFound::NoStreamsFound
NoStreamsFound(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:294
openshot::ErrorEncodingVideo
Exception when encoding audio packet.
Definition: Exceptions.h:142
openshot::OutOfMemory::OutOfMemory
OutOfMemory(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:357
openshot::ResampleError
Exception when resample fails.
Definition: Exceptions.h:378
openshot::InvalidJSONKey::py_message
std::string py_message() const override
Definition: Exceptions.h:275
openshot::InvalidSampleRate::~InvalidSampleRate
virtual ~InvalidSampleRate() noexcept
Definition: Exceptions.h:258
openshot::InvalidJSON
Exception for invalid JSON.
Definition: Exceptions.h:217
openshot::ChunkNotFound::ChunkNotFound
ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
Constructor.
Definition: Exceptions.h:91
openshot::WriterClosed::WriterClosed
WriterClosed(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:424
openshot::InvalidJSON::InvalidJSON
InvalidJSON(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:226
openshot::OutOfMemory
Exception when memory could not be allocated.
Definition: Exceptions.h:348
openshot::ExceptionBase
Base exception class with a custom message variable.
Definition: Exceptions.h:27
openshot::ErrorEncodingVideo::~ErrorEncodingVideo
virtual ~ErrorEncodingVideo() noexcept
Definition: Exceptions.h:153
openshot::ErrorEncodingVideo::ErrorEncodingVideo
ErrorEncodingVideo(std::string message, int64_t frame_number=-1)
Constructor.
Definition: Exceptions.h:151
openshot::ExceptionBase::m_message
std::string m_message
Definition: Exceptions.h:30
openshot::OutOfBoundsFrame::OutOfBoundsFrame
OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames)
Constructor.
Definition: Exceptions.h:312
openshot::OutOfBoundsFrame::FrameRequested
int64_t FrameRequested
Definition: Exceptions.h:303
openshot::ChunkNotFound::chunk_frame
int64_t chunk_frame
Definition: Exceptions.h:82
openshot::OutOfBoundsPoint::OutOfBoundsPoint
OutOfBoundsPoint(std::string message, int point_requested, int max_points)
Constructor.
Definition: Exceptions.h:336
openshot::ExceptionBase::~ExceptionBase
virtual ~ExceptionBase() noexcept
Definition: Exceptions.h:33
openshot::TooManySeeks::~TooManySeeks
virtual ~TooManySeeks() noexcept
Definition: Exceptions.h:410
openshot::OutOfBoundsFrame::py_message
std::string py_message() const override
Definition: Exceptions.h:315
openshot::InvalidJSON::~InvalidJSON
virtual ~InvalidJSON() noexcept
Definition: Exceptions.h:228
openshot::OutOfBoundsPoint::~OutOfBoundsPoint
virtual ~OutOfBoundsPoint() noexcept
Definition: Exceptions.h:338
openshot::ExceptionBase::ExceptionBase
ExceptionBase(std::string message)
Definition: Exceptions.h:32
openshot::InvalidFile
Exception for files that can not be found or opened.
Definition: Exceptions.h:187
openshot::FrameExceptionBase::FrameExceptionBase
FrameExceptionBase(std::string message, int64_t frame_number=-1)
Definition: Exceptions.h:48
openshot::OutOfBoundsPoint::MaxPoints
int MaxPoints
Definition: Exceptions.h:328
openshot::ErrorDecodingAudio::ErrorDecodingAudio
ErrorDecodingAudio(std::string message, int64_t frame_number=-1)
Constructor.
Definition: Exceptions.h:121
openshot::InvalidFile::~InvalidFile
virtual ~InvalidFile() noexcept
Definition: Exceptions.h:198
openshot::ReaderClosed
Exception when a reader is closed, and a frame is requested.
Definition: Exceptions.h:363
openshot::ExceptionBase::py_message
virtual std::string py_message() const
Definition: Exceptions.h:38
openshot::InvalidJSONKey::json
std::string json
Definition: Exceptions.h:265
openshot::FileExceptionBase::FileExceptionBase
FileExceptionBase(std::string message, std::string file_path="")
Definition: Exceptions.h:65
openshot::TooManySeeks::TooManySeeks
TooManySeeks(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:408
openshot::FileExceptionBase::py_message
virtual std::string py_message() const override
Definition: Exceptions.h:67
openshot::InvalidFile::InvalidFile
InvalidFile(std::string message, std::string file_path)
Constructor.
Definition: Exceptions.h:196
openshot::InvalidFormat::InvalidFormat
InvalidFormat(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:211
openshot::InvalidCodec::~InvalidCodec
virtual ~InvalidCodec() noexcept
Definition: Exceptions.h:183
openshot::ErrorDecodingAudio::~ErrorDecodingAudio
virtual ~ErrorDecodingAudio() noexcept
Definition: Exceptions.h:123
openshot::OutOfBoundsPoint::PointRequested
int PointRequested
Definition: Exceptions.h:327
openshot::InvalidChannels
Exception when an invalid # of audio channels are detected.
Definition: Exceptions.h:157
openshot::InvalidFormat::~InvalidFormat
virtual ~InvalidFormat() noexcept
Definition: Exceptions.h:213
openshot::ExceptionBase::what
virtual const char * what() const noexcept
Definition: Exceptions.h:34
openshot::OutOfBoundsPoint::py_message
std::string py_message() const override
Definition: Exceptions.h:339
openshot::InvalidOptions::~InvalidOptions
virtual ~InvalidOptions() noexcept
Definition: Exceptions.h:243
openshot::InvalidSampleRate::InvalidSampleRate
InvalidSampleRate(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:256
TMS_DEP_MSG
#define TMS_DEP_MSG
Definition: Exceptions.h:392
openshot::InvalidOptions
Exception when invalid encoding options are used.
Definition: Exceptions.h:232
openshot::ErrorDecodingAudio
Exception when decoding audio packet.
Definition: Exceptions.h:112
openshot::NoStreamsFound
Exception when no streams are found in the file.
Definition: Exceptions.h:285
openshot::InvalidChannels::~InvalidChannels
virtual ~InvalidChannels() noexcept
Definition: Exceptions.h:168
openshot::InvalidJSONKey
Exception for missing JSON Change key.
Definition: Exceptions.h:262
openshot::ResampleError::~ResampleError
virtual ~ResampleError() noexcept
Definition: Exceptions.h:389
openshot::FrameExceptionBase
Definition: Exceptions.h:44