Skip to content

Commit 8076514

Browse files
committed
Exceptions.h: fixes for noexcept, unused vars, std::
Some fixes for `-Wall`-readiness: * Removed `using namespace std;` from the header and added `std::` prefixes where needed (`std::string`) * Replaced `throw ()` in declarations with `noexcept`, as `throw ()` is [deprecated in c++11][1] * Several exception classes had a `file_path` member variable, despite never using it. Removed the unused class member. [1]:<https://en.cppreference.com/w/cpp/language/noexcept_spec>
1 parent 25b5225 commit 8076514

File tree

1 file changed

+60
-65
lines changed

1 file changed

+60
-65
lines changed

include/Exceptions.h

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#define OPENSHOT_EXCEPTIONS_H
3333

3434
#include <string>
35-
using namespace std;
3635

3736
namespace openshot {
3837

@@ -45,11 +44,11 @@ namespace openshot {
4544
class BaseException : public std::exception //: public exception
4645
{
4746
protected:
48-
string m_message;
47+
std::string m_message;
4948
public:
50-
BaseException(string message) : m_message(message) { }
51-
virtual ~BaseException() throw () {}
52-
virtual const char* what() const throw () {
49+
BaseException(std::string message) : m_message(message) { }
50+
virtual ~BaseException() noexcept {}
51+
virtual const char* what() const noexcept {
5352
// return custom message
5453
return m_message.c_str();
5554
}
@@ -59,146 +58,142 @@ namespace openshot {
5958
class ChunkNotFound : public BaseException
6059
{
6160
public:
62-
string file_path;
6361
int64_t frame_number;
6462
int64_t chunk_number;
6563
int64_t chunk_frame;
66-
ChunkNotFound(string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
64+
ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame)
6765
: BaseException(message), frame_number(frame_number), chunk_number(chunk_number), chunk_frame(chunk_frame) { }
68-
virtual ~ChunkNotFound() throw () {}
66+
virtual ~ChunkNotFound() noexcept {}
6967
};
7068

7169

7270
/// Exception when accessing a blackmagic decklink card
7371
class DecklinkError : public BaseException
7472
{
7573
public:
76-
DecklinkError(string message)
74+
DecklinkError(std::string message)
7775
: BaseException(message) { }
78-
virtual ~DecklinkError() throw () {}
76+
virtual ~DecklinkError() noexcept {}
7977
};
8078

8179
/// Exception when decoding audio packet
8280
class ErrorDecodingAudio : public BaseException
8381
{
8482
public:
85-
string file_path;
8683
int64_t frame_number;
87-
ErrorDecodingAudio(string message, int64_t frame_number)
84+
ErrorDecodingAudio(std::string message, int64_t frame_number)
8885
: BaseException(message), frame_number(frame_number) { }
89-
virtual ~ErrorDecodingAudio() throw () {}
86+
virtual ~ErrorDecodingAudio() noexcept {}
9087
};
9188

9289
/// Exception when encoding audio packet
9390
class ErrorEncodingAudio : public BaseException
9491
{
9592
public:
96-
string file_path;
9793
int64_t frame_number;
98-
ErrorEncodingAudio(string message, int64_t frame_number)
94+
ErrorEncodingAudio(std::string message, int64_t frame_number)
9995
: BaseException(message), frame_number(frame_number) { }
100-
virtual ~ErrorEncodingAudio() throw () {}
96+
virtual ~ErrorEncodingAudio() noexcept {}
10197
};
10298

10399
/// Exception when encoding audio packet
104100
class ErrorEncodingVideo : public BaseException
105101
{
106102
public:
107-
string file_path;
108103
int64_t frame_number;
109-
ErrorEncodingVideo(string message, int64_t frame_number)
104+
ErrorEncodingVideo(std::string message, int64_t frame_number)
110105
: BaseException(message), frame_number(frame_number) { }
111-
virtual ~ErrorEncodingVideo() throw () {}
106+
virtual ~ErrorEncodingVideo() noexcept {}
112107
};
113108

114109
/// Exception when an invalid # of audio channels are detected
115110
class InvalidChannels : public BaseException
116111
{
117112
public:
118-
string file_path;
119-
InvalidChannels(string message, string file_path)
113+
std::string file_path;
114+
InvalidChannels(std::string message, std::string file_path)
120115
: BaseException(message), file_path(file_path) { }
121-
virtual ~InvalidChannels() throw () {}
116+
virtual ~InvalidChannels() noexcept {}
122117
};
123118

124119
/// Exception when no valid codec is found for a file
125120
class InvalidCodec : public BaseException
126121
{
127122
public:
128-
string file_path;
129-
InvalidCodec(string message, string file_path)
123+
std::string file_path;
124+
InvalidCodec(std::string message, std::string file_path)
130125
: BaseException(message), file_path(file_path) { }
131-
virtual ~InvalidCodec() throw () {}
126+
virtual ~InvalidCodec() noexcept {}
132127
};
133128

134129
/// Exception for files that can not be found or opened
135130
class InvalidFile : public BaseException
136131
{
137132
public:
138-
string file_path;
139-
InvalidFile(string message, string file_path)
133+
std::string file_path;
134+
InvalidFile(std::string message, std::string file_path)
140135
: BaseException(message), file_path(file_path) { }
141-
virtual ~InvalidFile() throw () {}
136+
virtual ~InvalidFile() noexcept {}
142137
};
143138

144139
/// Exception when no valid format is found for a file
145140
class InvalidFormat : public BaseException
146141
{
147142
public:
148-
string file_path;
149-
InvalidFormat(string message, string file_path)
143+
std::string file_path;
144+
InvalidFormat(std::string message, std::string file_path)
150145
: BaseException(message), file_path(file_path) { }
151-
virtual ~InvalidFormat() throw () {}
146+
virtual ~InvalidFormat() noexcept {}
152147
};
153148

154149
/// Exception for invalid JSON
155150
class InvalidJSON : public BaseException
156151
{
157152
public:
158-
string file_path;
159-
InvalidJSON(string message, string file_path)
153+
std::string file_path;
154+
InvalidJSON(std::string message, std::string file_path)
160155
: BaseException(message), file_path(file_path) { }
161-
virtual ~InvalidJSON() throw () {}
156+
virtual ~InvalidJSON() noexcept {}
162157
};
163158

164159
/// Exception when invalid encoding options are used
165160
class InvalidOptions : public BaseException
166161
{
167162
public:
168-
string file_path;
169-
InvalidOptions(string message, string file_path)
163+
std::string file_path;
164+
InvalidOptions(std::string message, std::string file_path)
170165
: BaseException(message), file_path(file_path) { }
171-
virtual ~InvalidOptions() throw () {}
166+
virtual ~InvalidOptions() noexcept {}
172167
};
173168

174169
/// Exception when invalid sample rate is detected during encoding
175170
class InvalidSampleRate : public BaseException
176171
{
177172
public:
178-
string file_path;
179-
InvalidSampleRate(string message, string file_path)
173+
std::string file_path;
174+
InvalidSampleRate(std::string message, std::string file_path)
180175
: BaseException(message), file_path(file_path) { }
181-
virtual ~InvalidSampleRate() throw () {}
176+
virtual ~InvalidSampleRate() noexcept {}
182177
};
183178

184179
/// Exception for missing JSON Change key
185180
class InvalidJSONKey : public BaseException
186181
{
187182
public:
188-
string json;
189-
InvalidJSONKey(string message, string json)
183+
std::string json;
184+
InvalidJSONKey(std::string message, std::string json)
190185
: BaseException(message), json(json) { }
191-
virtual ~InvalidJSONKey() throw () {}
186+
virtual ~InvalidJSONKey() noexcept {}
192187
};
193188

194189
/// Exception when no streams are found in the file
195190
class NoStreamsFound : public BaseException
196191
{
197192
public:
198-
string file_path;
199-
NoStreamsFound(string message, string file_path)
193+
std::string file_path;
194+
NoStreamsFound(std::string message, std::string file_path)
200195
: BaseException(message), file_path(file_path) { }
201-
virtual ~NoStreamsFound() throw () {}
196+
virtual ~NoStreamsFound() noexcept {}
202197
};
203198

204199
/// Exception for frames that are out of bounds.
@@ -207,9 +202,9 @@ namespace openshot {
207202
public:
208203
int64_t FrameRequested;
209204
int64_t MaxFrames;
210-
OutOfBoundsFrame(string message, int64_t frame_requested, int64_t max_frames)
205+
OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames)
211206
: BaseException(message), FrameRequested(frame_requested), MaxFrames(max_frames) { }
212-
virtual ~OutOfBoundsFrame() throw () {}
207+
virtual ~OutOfBoundsFrame() noexcept {}
213208
};
214209

215210
/// Exception for an out of bounds key-frame point.
@@ -218,59 +213,59 @@ namespace openshot {
218213
public:
219214
int PointRequested;
220215
int MaxPoints;
221-
OutOfBoundsPoint(string message, int point_requested, int max_points)
216+
OutOfBoundsPoint(std::string message, int point_requested, int max_points)
222217
: BaseException(message), PointRequested(point_requested), MaxPoints(max_points) { }
223-
virtual ~OutOfBoundsPoint() throw () {}
218+
virtual ~OutOfBoundsPoint() noexcept {}
224219
};
225220

226221
/// Exception when memory could not be allocated
227222
class OutOfMemory : public BaseException
228223
{
229224
public:
230-
string file_path;
231-
OutOfMemory(string message, string file_path)
225+
std::string file_path;
226+
OutOfMemory(std::string message, std::string file_path)
232227
: BaseException(message), file_path(file_path) { }
233-
virtual ~OutOfMemory() throw () {}
228+
virtual ~OutOfMemory() noexcept {}
234229
};
235230

236231
/// Exception when a reader is closed, and a frame is requested
237232
class ReaderClosed : public BaseException
238233
{
239234
public:
240-
string file_path;
241-
ReaderClosed(string message, string file_path)
235+
std::string file_path;
236+
ReaderClosed(std::string message, std::string file_path)
242237
: BaseException(message), file_path(file_path) { }
243-
virtual ~ReaderClosed() throw () {}
238+
virtual ~ReaderClosed() noexcept {}
244239
};
245240

246241
/// Exception when resample fails
247242
class ResampleError : public BaseException
248243
{
249244
public:
250-
string file_path;
251-
ResampleError(string message, string file_path)
245+
std::string file_path;
246+
ResampleError(std::string message, std::string file_path)
252247
: BaseException(message), file_path(file_path) { }
253-
virtual ~ResampleError() throw () {}
248+
virtual ~ResampleError() noexcept {}
254249
};
255250

256251
/// Exception when too many seek attempts happen
257252
class TooManySeeks : public BaseException
258253
{
259254
public:
260-
string file_path;
261-
TooManySeeks(string message, string file_path)
255+
std::string file_path;
256+
TooManySeeks(std::string message, std::string file_path)
262257
: BaseException(message), file_path(file_path) { }
263-
virtual ~TooManySeeks() throw () {}
258+
virtual ~TooManySeeks() noexcept {}
264259
};
265260

266261
/// Exception when a writer is closed, and a frame is requested
267262
class WriterClosed : public BaseException
268263
{
269264
public:
270-
string file_path;
271-
WriterClosed(string message, string file_path)
265+
std::string file_path;
266+
WriterClosed(std::string message, std::string file_path)
272267
: BaseException(message), file_path(file_path) { }
273-
virtual ~WriterClosed() throw () {}
268+
virtual ~WriterClosed() noexcept {}
274269
};
275270
}
276271

0 commit comments

Comments
 (0)