diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-05-22 12:27:17 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-05-22 12:27:17 +0000 |
| commit | 4259514395a7f08f4cf58b8f247a504eb4e754b8 (patch) | |
| tree | 10bf4da6fe6b4222a2be3e6fd7ac1aeed6061169 /src/bencode.cc | |
| parent | a839b427476fdb0daa5f090cdbe59658b4edfd6e (diff) | |
2009-05-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made exception message more verbose.
* src/bencode.cc
Diffstat (limited to 'src/bencode.cc')
| -rw-r--r-- | src/bencode.cc | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/bencode.cc b/src/bencode.cc index 324d82cf..01d16422 100644 --- a/src/bencode.cc +++ b/src/bencode.cc @@ -51,7 +51,8 @@ static void checkdelim(std::istream& ss, const char delim = ':') char d; if(!(ss.get(d) && d == delim)) { throw DL_ABORT_EX - (StringFormat("Delimiter '%c' not found.", delim).str()); + (StringFormat("Bencode decoding failed: Delimiter '%c' not found.", + delim).str()); } } @@ -60,7 +61,8 @@ static std::string decoderawstring(std::istream& ss) int length; ss >> length; if(!ss || length < 0) { - throw DL_ABORT_EX("A positive integer expected but none found."); + throw DL_ABORT_EX("Bencode decoding failed:" + " A positive integer expected but none found."); } // TODO check length, it must be less than or equal to INT_MAX checkdelim(ss); @@ -70,7 +72,8 @@ static std::string decoderawstring(std::istream& ss) delete [] buf; if(ss.gcount() != static_cast<int>(length)) { throw DL_ABORT_EX - (StringFormat("Expected %lu bytes of data, but only %d read.", + (StringFormat("Bencode decoding failed:" + " Expected %lu bytes of data, but only %d read.", static_cast<unsigned long>(length), ss.gcount()).str()); } return str; @@ -86,7 +89,8 @@ static BDE decodeinteger(std::istream& ss) BDE::Integer integer; ss >> integer; if(!ss) { - throw DL_ABORT_EX("Integer expected but none found"); + throw DL_ABORT_EX("Bencode decoding failed:" + " Integer expected but none found"); } checkdelim(ss, 'e'); return BDE(integer); @@ -105,7 +109,8 @@ static BDE decodedict(std::istream& ss) dict[key] = decodeiter(ss); } } - throw DL_ABORT_EX("Unexpected EOF in dict context. 'e' expected."); + throw DL_ABORT_EX("Bencode decoding failed:" + " Unexpected EOF in dict context. 'e' expected."); } static BDE decodelist(std::istream& ss) @@ -120,15 +125,17 @@ static BDE decodelist(std::istream& ss) list << decodeiter(ss); } } - throw DL_ABORT_EX("Unexpected EOF in list context. 'e' expected."); + throw DL_ABORT_EX("Bencode decoding failed:" + " Unexpected EOF in list context. 'e' expected."); } static BDE decodeiter(std::istream& ss) { char c; if(!ss.get(c)) { - throw DL_ABORT_EX("Unexpected EOF in term context." - " 'd', 'l', 'i' or digit is expected."); + throw DL_ABORT_EX("Bencode decoding failed:" + " Unexpected EOF in term context." + " 'd', 'l', 'i' or digit is expected."); } if(c == 'd') { return decodedict(ss); @@ -169,7 +176,8 @@ BDE decodeFromFile(const std::string& filename) return decode(f); } else { throw DL_ABORT_EX - (StringFormat("Cannot open file '%s'.", filename.c_str()).str()); + (StringFormat("Bencode decoding failed:" + " Cannot open file '%s'.", filename.c_str()).str()); } } |
