]> git.tdb.fi Git - libs/net.git/commitdiff
Exception changes
authorMikko Rasa <tdb@tdb.fi>
Wed, 10 Aug 2011 18:05:12 +0000 (21:05 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 10 Aug 2011 18:05:12 +0000 (21:05 +0300)
source/message.cpp
source/request.cpp
source/response.cpp
source/server.cpp
source/utils.cpp
source/version.cpp

index f1e4c286bd13031c1918d21cebacec189200223c..c9638d0a05b3d938e0cb6b876df59fa80686e901 100644 (file)
@@ -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)));
 
index 31e9c7c201959f158e6443556775d9bdfe4095eb..c948755ae78281cb1c36378de491a1cd0c948cd7 100644 (file)
@@ -27,7 +27,7 @@ Request Request::parse(const string &str)
        unsigned lf = str.find('\n');
        vector<string> 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 = "/";
index a5f95825c1c65fc8170552e4046083fea12db828..ede249b7e11afa467e5423f4c4a54faa091fc59c 100644 (file)
@@ -26,7 +26,7 @@ Response Response::parse(const string &str)
        unsigned lf = str.find('\n');
        vector<string> 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<Status>(lexical_cast<unsigned>(parts[1]));
index 677bc6c43b5e52fc7048594177b7d3d3bad005b4..259d13b087598d5ae602f1c4b16e7ec6ed24259e 100644 (file)
@@ -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");
 }
 
 
index 0803c14c74edc980951e50b8c960ebcb94481622..5a5dc0487c0f1bf4dbd9132143e14567d7c30574 100644 (file)
@@ -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<unsigned char>(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+"://";
index e7ed6aaafb5e301ba20f5b3d1db8df8d47257449..f22b46eafe92523497d25403c3c772fd1fe46676 100644 (file)
@@ -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<unsigned>(match[1].str)<<4 | lexical_cast<unsigned>(match[2].str);
        else
-               throw InvalidParameterValue("Invalid HTTP version");
+               throw invalid_argument("parse_version");
 }
 
 string version_str(Version ver)