Add ParseException.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2019-12-31 13:29:45 +01:00
parent 71783b2638
commit 7267981c37
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
5 changed files with 30 additions and 0 deletions

View File

@ -165,6 +165,7 @@ SOCKS proxy support yet, sorry.
| 3 | File error.
| 4 | Mastodon API error.
| 5 | JSON error, most likely the file is wrongly formatted.
| 6 | Feed parse error. Usually the type of feed could not be detected.
| 9 | Unknown error.
|===============================================================================

View File

@ -141,6 +141,8 @@ void Document::parse()
BOOST_LOG_TRIVIAL(debug) << "RSS detected.";
parse_rss(tree);
}
ParseException{"Could not detect type of feed."};
}
void Document::parse_rss(const pt::ptree &tree)

View File

@ -63,4 +63,13 @@ const char *FileException::what() const noexcept
{
return _message.c_str();
}
ParseException::ParseException(string message)
: _message{move(message)}
{}
const char *ParseException::what() const noexcept
{
return _message.c_str();
}
} // namespace mastorss

View File

@ -68,6 +68,18 @@ public:
[[nodiscard]]
const char *what() const noexcept override;
private:
const string _message;
};
class ParseException : public exception
{
public:
explicit ParseException(string message);
[[nodiscard]]
const char *what() const noexcept override;
private:
const string _message;
};

View File

@ -28,6 +28,7 @@ constexpr int network = 2;
constexpr int file = 3;
constexpr int mastodon = 4;
constexpr int json = 5;
constexpr int parse = 6;
constexpr int unknown = 9;
} // namespace error
@ -142,6 +143,11 @@ int main(int argc, char *argv[])
cerr << "JSON error:\n" << e.what() << '\n';
return error::json;
}
catch (const ParseException &e)
{
cerr << e.what() << '\n';
return error::parse;
}
catch (const runtime_error &e)
{
cerr << e.what() << '\n';