OpenShot Library | libopenshot 0.6.0
Loading...
Searching...
No Matches
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
19namespace 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)
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;
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:
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
402 class
403 [[deprecated(TMS_DEP_MSG)]]
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
#define TMS_DEP_MSG
Definition Exceptions.h:398
Exception when a required chunk is missing.
Definition Exceptions.h:85
ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
Constructor.
Definition Exceptions.h:97
virtual ~ChunkNotFound() noexcept
Definition Exceptions.h:99
Exception when accessing a blackmagic decklink card.
Definition Exceptions.h:105
DecklinkError(std::string message)
Constructor.
Definition Exceptions.h:112
virtual ~DecklinkError() noexcept
Definition Exceptions.h:114
Exception when decoding audio packet.
Definition Exceptions.h:119
virtual ~ErrorDecodingAudio() noexcept
Definition Exceptions.h:129
ErrorDecodingAudio(std::string message, int64_t frame_number=-1)
Constructor.
Definition Exceptions.h:127
Exception when encoding audio packet.
Definition Exceptions.h:134
ErrorEncodingAudio(std::string message, int64_t frame_number=-1)
Constructor.
Definition Exceptions.h:142
virtual ~ErrorEncodingAudio() noexcept
Definition Exceptions.h:144
Exception when encoding audio packet.
Definition Exceptions.h:149
virtual ~ErrorEncodingVideo() noexcept
Definition Exceptions.h:159
ErrorEncodingVideo(std::string message, int64_t frame_number=-1)
Constructor.
Definition Exceptions.h:157
Base exception class with a custom message variable.
Definition Exceptions.h:28
virtual ~ExceptionBase() noexcept
Definition Exceptions.h:33
virtual std::string py_message() const
Definition Exceptions.h:38
ExceptionBase(std::string message)
Definition Exceptions.h:32
virtual const char * what() const noexcept
Definition Exceptions.h:34
virtual const char * what() const noexcept override
Definition Exceptions.h:73
FileExceptionBase(std::string message, std::string file_path="")
Definition Exceptions.h:66
virtual std::string py_message() const override
Definition Exceptions.h:77
FrameExceptionBase(std::string message, int64_t frame_number=-1)
Definition Exceptions.h:48
virtual std::string py_message() const override
Definition Exceptions.h:50
Exception when an invalid # of audio channels are detected.
Definition Exceptions.h:164
InvalidChannels(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:172
virtual ~InvalidChannels() noexcept
Definition Exceptions.h:174
Exception when no valid codec is found for a file.
Definition Exceptions.h:179
InvalidCodec(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:187
virtual ~InvalidCodec() noexcept
Definition Exceptions.h:189
Exception for files that can not be found or opened.
Definition Exceptions.h:194
InvalidFile(std::string message, std::string file_path)
Constructor.
Definition Exceptions.h:202
virtual ~InvalidFile() noexcept
Definition Exceptions.h:204
Exception when no valid format is found for a file.
Definition Exceptions.h:209
virtual ~InvalidFormat() noexcept
Definition Exceptions.h:219
InvalidFormat(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:217
Exception for missing JSON Change key.
Definition Exceptions.h:269
std::string py_message() const override
Definition Exceptions.h:281
virtual ~InvalidJSONKey() noexcept
Definition Exceptions.h:280
InvalidJSONKey(std::string message, std::string json)
Constructor.
Definition Exceptions.h:278
Exception for invalid JSON.
Definition Exceptions.h:224
virtual ~InvalidJSON() noexcept
Definition Exceptions.h:234
InvalidJSON(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:232
Exception when invalid encoding options are used.
Definition Exceptions.h:239
InvalidOptions(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:247
virtual ~InvalidOptions() noexcept
Definition Exceptions.h:249
Exception when invalid sample rate is detected during encoding.
Definition Exceptions.h:254
virtual ~InvalidSampleRate() noexcept
Definition Exceptions.h:264
InvalidSampleRate(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:262
Exception when no streams are found in the file.
Definition Exceptions.h:292
NoStreamsFound(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:300
virtual ~NoStreamsFound() noexcept
Definition Exceptions.h:302
Exception for frames that are out of bounds.
Definition Exceptions.h:307
OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames)
Constructor.
Definition Exceptions.h:318
virtual ~OutOfBoundsFrame() noexcept
Definition Exceptions.h:320
std::string py_message() const override
Definition Exceptions.h:321
Exception for an out of bounds key-frame point.
Definition Exceptions.h:331
std::string py_message() const override
Definition Exceptions.h:345
virtual ~OutOfBoundsPoint() noexcept
Definition Exceptions.h:344
OutOfBoundsPoint(std::string message, int point_requested, int max_points)
Constructor.
Definition Exceptions.h:342
Exception when memory could not be allocated.
Definition Exceptions.h:355
virtual ~OutOfMemory() noexcept
Definition Exceptions.h:365
OutOfMemory(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:363
Exception when a reader is closed, and a frame is requested.
Definition Exceptions.h:370
virtual ~ReaderClosed() noexcept
Definition Exceptions.h:380
ReaderClosed(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:378
Exception when resample fails.
Definition Exceptions.h:385
virtual ~ResampleError() noexcept
Definition Exceptions.h:395
ResampleError(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:393
Exception when too many seek attempts happen.
Definition Exceptions.h:405
virtual ~TooManySeeks() noexcept
Definition Exceptions.h:416
TooManySeeks(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:414
Exception when a writer is closed, and a frame is requested.
Definition Exceptions.h:422
WriterClosed(std::string message, std::string file_path="")
Constructor.
Definition Exceptions.h:430
virtual ~WriterClosed() noexcept
Definition Exceptions.h:432
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29