PlaylistError: add exception class wrapping enum PlaylistResult

This commit is contained in:
Max Kellermann
2015-12-18 09:21:11 +01:00
parent 7562c5751c
commit 8bb5a565cd
8 changed files with 132 additions and 134 deletions

View File

@@ -20,6 +20,8 @@
#ifndef MPD_PLAYLIST_ERROR_HXX
#define MPD_PLAYLIST_ERROR_HXX
#include <stdexcept>
class Domain;
enum class PlaylistResult {
@@ -37,4 +39,26 @@ enum class PlaylistResult {
extern const Domain playlist_domain;
class PlaylistError : public std::runtime_error {
PlaylistResult code;
public:
PlaylistError(PlaylistResult _code, const char *msg)
:std::runtime_error(msg), code(_code) {}
PlaylistResult GetCode() const {
return code;
}
static PlaylistError NoSuchSong() {
return PlaylistError(PlaylistResult::BAD_RANGE,
"No such song");
}
static PlaylistError BadRange() {
return PlaylistError(PlaylistResult::BAD_RANGE,
"Bad song index");
}
};
#endif