From 7b84e8b9d560e868f7fafbc18a2770579ee1b4b3 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 10 Aug 2011 21:05:12 +0300 Subject: [PATCH] Exception changes --- source/message.cpp | 4 ++-- source/request.cpp | 5 +++-- source/response.cpp | 2 +- source/server.cpp | 3 ++- source/utils.cpp | 7 ++++--- source/version.cpp | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/message.cpp b/source/message.cpp index f1e4c28..c9638d0 100644 --- a/source/message.cpp +++ b/source/message.cpp @@ -105,13 +105,13 @@ unsigned Message::parse_headers(const string &d) { unsigned lf = d.find('\n', start); if(lf==string::npos) - throw InvalidParameterValue("Incomplete response"); + throw invalid_argument("Message::parse_headers"); if(lf==start || (d[start]=='\r' && lf==start+1)) return lf+1; unsigned colon = d.find(':', start); if(colon>lf) - throw InvalidParameterValue("No colon in header"); + throw invalid_argument("Message::parse_headers"); set_header(d.substr(start, colon-start), strip(d.substr(colon+1, lf-colon-1))); diff --git a/source/request.cpp b/source/request.cpp index 31e9c7c..c948755 100644 --- a/source/request.cpp +++ b/source/request.cpp @@ -27,7 +27,7 @@ Request Request::parse(const string &str) unsigned lf = str.find('\n'); vector parts = split(str.substr(0, lf-(str[lf-1]=='\r')), ' ', 2); if(parts.size()<3) - throw InvalidParameterValue("Invalid request"); + throw invalid_argument("Request::parse"); Request result(parts[0], parts[1]); result.http_version = parse_version(parts[2]); @@ -43,7 +43,8 @@ Request Request::from_url(const string &str) { Url url = parse_url(str); if(url.scheme!="http") - throw InvalidParameterValue("Only http scheme is supported"); + throw invalid_argument("Request::from_url"); + string path = url.path; if(path.empty()) path = "/"; diff --git a/source/response.cpp b/source/response.cpp index a5f9582..ede249b 100644 --- a/source/response.cpp +++ b/source/response.cpp @@ -26,7 +26,7 @@ Response Response::parse(const string &str) unsigned lf = str.find('\n'); vector parts = split(str.substr(0, lf), ' ', 2); if(parts.size()<2) - throw InvalidParameterValue("Invalid response"); + throw invalid_argument("Response::parse"); result.http_version = parse_version(parts[0]); result.status = static_cast(lexical_cast(parts[1])); diff --git a/source/server.cpp b/source/server.cpp index 677bc6c..259d13b 100644 --- a/source/server.cpp +++ b/source/server.cpp @@ -160,7 +160,8 @@ Server::Client &Server::get_client_by_response(Response &resp) if(i->response==&resp) return *i; - throw InvalidParameterValue("Response does not belong to any client"); + // XXX Do this differently + throw invalid_argument("Response does not belong to any client"); } diff --git a/source/utils.cpp b/source/utils.cpp index 0803c14..5a5dc04 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -65,7 +65,7 @@ string urldecode(const string &str) if(c=='%') { if(i+3>str.size()) - throw InvalidParameterValue("Malformed data"); + throw invalid_argument("urldecode"); result += lexical_cast(str.substr(i+1, 2), "x"); i += 2; } @@ -91,13 +91,14 @@ Url parse_url(const string &str) return url; } else - throw InvalidParameterValue("Invalid URL"); + throw invalid_argument("parse_url"); } string build_url(const Url &url) { if(!url.path.empty() && url.path[0]!='/') - throw InvalidParameterValue("Only absolute paths are supported"); + throw invalid_argument("build_url"); + string str; if(!url.scheme.empty()) str += url.scheme+"://"; diff --git a/source/version.cpp b/source/version.cpp index e7ed6aa..f22b46e 100644 --- a/source/version.cpp +++ b/source/version.cpp @@ -13,7 +13,7 @@ Version parse_version(const std::string &ver) if(RegMatch match = Regex("^HTTP/([0-9]+).([0-9]+)$").match(ver)) return lexical_cast(match[1].str)<<4 | lexical_cast(match[2].str); else - throw InvalidParameterValue("Invalid HTTP version"); + throw invalid_argument("parse_version"); } string version_str(Version ver) -- 2.43.0