OpenShot Library | libopenshot  0.5.0
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  std::string full_message;
66  FileExceptionBase(std::string message, std::string file_path="")
67  : ExceptionBase(message),
69  full_message(message +
70  (file_path != ""
71  ? " for file " + file_path
72  : "")) { }
73  virtual const char* what() const noexcept override {
74  // Include file path in native C++ exception output (stderr / terminate).
75  return full_message.c_str();
76  }
77  virtual std::string py_message() const override {
78  // Keep Python exception output consistent with what().
79  return full_message;
80  }
81  };
82 
85  {
86  public:
87  int64_t chunk_number;
88  int64_t chunk_frame;
97  ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
99  virtual ~ChunkNotFound() noexcept {}
100  };
101 
102 
105  {
106  public:
112  DecklinkError(std::string message)
113  : ExceptionBase(message) { }
114  virtual ~DecklinkError() noexcept {}
115  };
116 
119  {
120  public:
127  ErrorDecodingAudio(std::string message, int64_t frame_number=-1)
128  : FrameExceptionBase(message, frame_number) { }
129  virtual ~ErrorDecodingAudio() noexcept {}
130  };
131 
134  {
135  public:
142  ErrorEncodingAudio(std::string message, int64_t frame_number=-1)
143  : FrameExceptionBase(message, frame_number) { }
144  virtual ~ErrorEncodingAudio() noexcept {}
145  };
146 
149  {
150  public:
157  ErrorEncodingVideo(std::string message, int64_t frame_number=-1)
158  : FrameExceptionBase(message, frame_number) { }
159  virtual ~ErrorEncodingVideo() noexcept {}
160  };
161 
164  {
165  public:
172  InvalidChannels(std::string message, std::string file_path="")
173  : FileExceptionBase(message, file_path) { }
174  virtual ~InvalidChannels() noexcept {}
175  };
176 
179  {
180  public:
187  InvalidCodec(std::string message, std::string file_path="")
188  : FileExceptionBase(message, file_path) { }
189  virtual ~InvalidCodec() noexcept {}
190  };
191 
194  {
195  public:
202  InvalidFile(std::string message, std::string file_path)
203  : FileExceptionBase(message, file_path) { }
204  virtual ~InvalidFile() noexcept {}
205  };
206 
209  {
210  public:
217  InvalidFormat(std::string message, std::string file_path="")
218  : FileExceptionBase(message, file_path) { }
219  virtual ~InvalidFormat() noexcept {}
220  };
221 
224  {
225  public:
232  InvalidJSON(std::string message, std::string file_path="")
233  : FileExceptionBase(message, file_path) { }
234  virtual ~InvalidJSON() noexcept {}
235  };
236 
239  {
240  public:
247  InvalidOptions(std::string message, std::string file_path="")
248  : FileExceptionBase(message, file_path) { }
249  virtual ~InvalidOptions() noexcept {}
250  };
251 
254  {
255  public:
262  InvalidSampleRate(std::string message, std::string file_path="")
263  : FileExceptionBase(message, file_path) { }
264  virtual ~InvalidSampleRate() noexcept {}
265  };
266 
269  {
270  public:
271  std::string json;
278  InvalidJSONKey(std::string message, std::string json)
279  : ExceptionBase(message), json(json) { }
280  virtual ~InvalidJSONKey() noexcept {}
281  std::string py_message() const override {
282  std::string out_msg = m_message +
283  " for JSON data " +
284  (json.size() > 100 ? " (abbreviated): " : ": ")
285  + json.substr(0, 99);
286  return out_msg;
287  }
288  };
289 
292  {
293  public:
300  NoStreamsFound(std::string message, std::string file_path="")
301  : FileExceptionBase(message, file_path) { }
302  virtual ~NoStreamsFound() noexcept {}
303  };
304 
307  {
308  public:
309  int64_t FrameRequested;
310  int64_t MaxFrames;
318  OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames)
319  : ExceptionBase(message), FrameRequested(frame_requested), MaxFrames(max_frames) { }
320  virtual ~OutOfBoundsFrame() noexcept {}
321  std::string py_message() const override {
322  std::string out_msg(m_message
323  + " Frame requested: " + std::to_string(FrameRequested)
324  + " Max frames: " + std::to_string(MaxFrames));
325  return out_msg;
326  }
327  };
328 
331  {
332  public:
342  OutOfBoundsPoint(std::string message, int point_requested, int max_points)
343  : ExceptionBase(message), PointRequested(point_requested), MaxPoints(max_points) { }
344  virtual ~OutOfBoundsPoint() noexcept {}
345  std::string py_message() const override {
346  std::string out_msg(m_message
347  + " Point requested: " + std::to_string(PointRequested)
348  + " Max point: " + std::to_string(MaxPoints));
349  return out_msg;
350  }
351  };
352 
355  {
356  public:
363  OutOfMemory(std::string message, std::string file_path="")
364  : FileExceptionBase(message, file_path) { }
365  virtual ~OutOfMemory() noexcept {}
366  };
367 
370  {
371  public:
378  ReaderClosed(std::string message, std::string file_path="")
379  : FileExceptionBase(message, file_path) { }
380  virtual ~ReaderClosed() noexcept {}
381  };
382 
385  {
386  public:
393  ResampleError(std::string message, std::string file_path="")
394  : FileExceptionBase(message, file_path) { }
395  virtual ~ResampleError() noexcept {}
396  };
397 
398 #define TMS_DEP_MSG "The library no longer throws this exception. It will be removed in a future release."
399 
400 #ifndef SWIG
401  class
403  [[deprecated(TMS_DEP_MSG)]]
404  TooManySeeks : public FileExceptionBase
405  {
406  public:
413  [[deprecated(TMS_DEP_MSG)]]
414  TooManySeeks(std::string message, std::string file_path="")
415  : FileExceptionBase(message, file_path) { }
416  virtual ~TooManySeeks() noexcept {}
417  };
418 #endif
419 
422  {
423  public:
430  WriterClosed(std::string message, std::string file_path="")
431  : FileExceptionBase(message, file_path) { }
432  virtual ~WriterClosed() noexcept {}
433  };
434 }
435 
436 #endif
openshot::InvalidOptions::InvalidOptions
InvalidOptions(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:247
openshot::InvalidFormat
Exception when no valid format is found for a file.
Definition: Exceptions.h:208
openshot::ReaderClosed::~ReaderClosed
virtual ~ReaderClosed() noexcept
Definition: Exceptions.h:380
openshot::InvalidSampleRate
Exception when invalid sample rate is detected during encoding.
Definition: Exceptions.h:253
openshot::InvalidCodec
Exception when no valid codec is found for a file.
Definition: Exceptions.h:178
openshot::WriterClosed
Exception when a writer is closed, and a frame is requested.
Definition: Exceptions.h:421
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:187
openshot::FileExceptionBase::full_message
std::string full_message
Definition: Exceptions.h:65
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:302
openshot::OutOfBoundsFrame::~OutOfBoundsFrame
virtual ~OutOfBoundsFrame() noexcept
Definition: Exceptions.h:320
openshot::InvalidJSONKey::~InvalidJSONKey
virtual ~InvalidJSONKey() noexcept
Definition: Exceptions.h:280
openshot::FileExceptionBase::what
virtual const char * what() const noexcept override
Definition: Exceptions.h:73
openshot::InvalidChannels::InvalidChannels
InvalidChannels(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:172
openshot::ChunkNotFound::~ChunkNotFound
virtual ~ChunkNotFound() noexcept
Definition: Exceptions.h:99
openshot::DecklinkError::~DecklinkError
virtual ~DecklinkError() noexcept
Definition: Exceptions.h:114
openshot::ResampleError::ResampleError
ResampleError(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:393
openshot::InvalidJSONKey::InvalidJSONKey
InvalidJSONKey(std::string message, std::string json)
Constructor.
Definition: Exceptions.h:278
openshot::ErrorEncodingAudio::ErrorEncodingAudio
ErrorEncodingAudio(std::string message, int64_t frame_number=-1)
Constructor.
Definition: Exceptions.h:142
openshot::OutOfBoundsFrame
Exception for frames that are out of bounds.
Definition: Exceptions.h:306
openshot::ErrorEncodingAudio
Exception when encoding audio packet.
Definition: Exceptions.h:133
openshot::ReaderClosed::ReaderClosed
ReaderClosed(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:378
openshot::ErrorEncodingAudio::~ErrorEncodingAudio
virtual ~ErrorEncodingAudio() noexcept
Definition: Exceptions.h:144
openshot::OutOfMemory::~OutOfMemory
virtual ~OutOfMemory() noexcept
Definition: Exceptions.h:365
openshot::WriterClosed::~WriterClosed
virtual ~WriterClosed() noexcept
Definition: Exceptions.h:432
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:104
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:330
openshot::ChunkNotFound::chunk_number
int64_t chunk_number
Definition: Exceptions.h:87
openshot::ChunkNotFound
Exception when a required chunk is missing.
Definition: Exceptions.h:84
openshot::DecklinkError::DecklinkError
DecklinkError(std::string message)
Constructor.
Definition: Exceptions.h:112
openshot::OutOfBoundsFrame::MaxFrames
int64_t MaxFrames
Definition: Exceptions.h:310
openshot::NoStreamsFound::NoStreamsFound
NoStreamsFound(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:300
openshot::ErrorEncodingVideo
Exception when encoding audio packet.
Definition: Exceptions.h:148
openshot::OutOfMemory::OutOfMemory
OutOfMemory(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:363
openshot::ResampleError
Exception when resample fails.
Definition: Exceptions.h:384
openshot::InvalidJSONKey::py_message
std::string py_message() const override
Definition: Exceptions.h:281
openshot::InvalidSampleRate::~InvalidSampleRate
virtual ~InvalidSampleRate() noexcept
Definition: Exceptions.h:264
openshot::InvalidJSON
Exception for invalid JSON.
Definition: Exceptions.h:223
openshot::ChunkNotFound::ChunkNotFound
ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
Constructor.
Definition: Exceptions.h:97
openshot::WriterClosed::WriterClosed
WriterClosed(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:430
openshot::InvalidJSON::InvalidJSON
InvalidJSON(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:232
openshot::OutOfMemory
Exception when memory could not be allocated.
Definition: Exceptions.h:354
openshot::ExceptionBase
Base exception class with a custom message variable.
Definition: Exceptions.h:27
openshot::ErrorEncodingVideo::~ErrorEncodingVideo
virtual ~ErrorEncodingVideo() noexcept
Definition: Exceptions.h:159
openshot::ErrorEncodingVideo::ErrorEncodingVideo
ErrorEncodingVideo(std::string message, int64_t frame_number=-1)
Constructor.
Definition: Exceptions.h:157
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:318
openshot::OutOfBoundsFrame::FrameRequested
int64_t FrameRequested
Definition: Exceptions.h:309
openshot::ChunkNotFound::chunk_frame
int64_t chunk_frame
Definition: Exceptions.h:88
openshot::OutOfBoundsPoint::OutOfBoundsPoint
OutOfBoundsPoint(std::string message, int point_requested, int max_points)
Constructor.
Definition: Exceptions.h:342
openshot::ExceptionBase::~ExceptionBase
virtual ~ExceptionBase() noexcept
Definition: Exceptions.h:33
openshot::TooManySeeks::~TooManySeeks
virtual ~TooManySeeks() noexcept
Definition: Exceptions.h:416
openshot::OutOfBoundsFrame::py_message
std::string py_message() const override
Definition: Exceptions.h:321
openshot::InvalidJSON::~InvalidJSON
virtual ~InvalidJSON() noexcept
Definition: Exceptions.h:234
openshot::OutOfBoundsPoint::~OutOfBoundsPoint
virtual ~OutOfBoundsPoint() noexcept
Definition: Exceptions.h:344
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:193
openshot::FrameExceptionBase::FrameExceptionBase
FrameExceptionBase(std::string message, int64_t frame_number=-1)
Definition: Exceptions.h:48
openshot::OutOfBoundsPoint::MaxPoints
int MaxPoints
Definition: Exceptions.h:334
openshot::ErrorDecodingAudio::ErrorDecodingAudio
ErrorDecodingAudio(std::string message, int64_t frame_number=-1)
Constructor.
Definition: Exceptions.h:127
openshot::InvalidFile::~InvalidFile
virtual ~InvalidFile() noexcept
Definition: Exceptions.h:204
openshot::ReaderClosed
Exception when a reader is closed, and a frame is requested.
Definition: Exceptions.h:369
openshot::ExceptionBase::py_message
virtual std::string py_message() const
Definition: Exceptions.h:38
openshot::InvalidJSONKey::json
std::string json
Definition: Exceptions.h:271
openshot::FileExceptionBase::FileExceptionBase
FileExceptionBase(std::string message, std::string file_path="")
Definition: Exceptions.h:66
openshot::TooManySeeks::TooManySeeks
TooManySeeks(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:414
openshot::FileExceptionBase::py_message
virtual std::string py_message() const override
Definition: Exceptions.h:77
openshot::InvalidFile::InvalidFile
InvalidFile(std::string message, std::string file_path)
Constructor.
Definition: Exceptions.h:202
openshot::InvalidFormat::InvalidFormat
InvalidFormat(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:217
openshot::InvalidCodec::~InvalidCodec
virtual ~InvalidCodec() noexcept
Definition: Exceptions.h:189
openshot::ErrorDecodingAudio::~ErrorDecodingAudio
virtual ~ErrorDecodingAudio() noexcept
Definition: Exceptions.h:129
openshot::OutOfBoundsPoint::PointRequested
int PointRequested
Definition: Exceptions.h:333
openshot::InvalidChannels
Exception when an invalid # of audio channels are detected.
Definition: Exceptions.h:163
openshot::InvalidFormat::~InvalidFormat
virtual ~InvalidFormat() noexcept
Definition: Exceptions.h:219
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:345
openshot::InvalidOptions::~InvalidOptions
virtual ~InvalidOptions() noexcept
Definition: Exceptions.h:249
openshot::InvalidSampleRate::InvalidSampleRate
InvalidSampleRate(std::string message, std::string file_path="")
Constructor.
Definition: Exceptions.h:262
TMS_DEP_MSG
#define TMS_DEP_MSG
Definition: Exceptions.h:398
openshot::InvalidOptions
Exception when invalid encoding options are used.
Definition: Exceptions.h:238
openshot::ErrorDecodingAudio
Exception when decoding audio packet.
Definition: Exceptions.h:118
openshot::NoStreamsFound
Exception when no streams are found in the file.
Definition: Exceptions.h:291
openshot::InvalidChannels::~InvalidChannels
virtual ~InvalidChannels() noexcept
Definition: Exceptions.h:174
openshot::InvalidJSONKey
Exception for missing JSON Change key.
Definition: Exceptions.h:268
openshot::ResampleError::~ResampleError
virtual ~ResampleError() noexcept
Definition: Exceptions.h:395
openshot::FrameExceptionBase
Definition: Exceptions.h:44