From edbd5db807dd66876ad25e0b67a37a567187f076 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 23 Aug 2015 11:19:30 +0800 Subject: Serialise - Clean up TODO for exception --- src/include/serialise.hpp | 13 +++++++++++++ src/serialise.cpp | 24 ++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/include/serialise.hpp b/src/include/serialise.hpp index 4b482f9b..0840d54b 100644 --- a/src/include/serialise.hpp +++ b/src/include/serialise.hpp @@ -23,6 +23,19 @@ class Deserialiser; #define SERIALISE_TYPE_A(method_prefix, tag_str, body) SERIALISE_TYPE(method_prefix, tag_str, body, body) #define SERIALISE_TYPE_S(class_, body) SERIALISE_TYPE(class_::, #class_, body, body) +class DeserialiseFailure: + public ::std::runtime_error +{ + const char *m_fcn; + const char *m_message; +public: + DeserialiseFailure(const char *fcn, const char *message): + ::std::runtime_error("Deserialise failure"), + m_fcn(fcn), + m_message(message) + {} +}; + class Serialisable { public: diff --git a/src/serialise.cpp b/src/serialise.cpp index 72a6dc50..fc662b4f 100644 --- a/src/serialise.cpp +++ b/src/serialise.cpp @@ -145,7 +145,7 @@ size_t Deserialiser_TextTree::start_array() eat_ws(); char c = getc(); if( c != '[' ) - throw ::std::runtime_error("TODO: Less shit exception, start_array"); + throw DeserialiseFailure("start_array", "no ["); eat_ws(); if( peekc() == ']' ) { @@ -156,7 +156,7 @@ size_t Deserialiser_TextTree::start_array() size_t len; m_is >> len; if( !m_is.good() ) - throw ::std::runtime_error("TODO: Less shit exception, start_array"); + throw DeserialiseFailure("start_array", "length missing"); DEBUG("len = "<> v; if( !m_is.good() ) - throw ::std::runtime_error("TODO: Less shit exception, item(uint64_t)"); + throw DeserialiseFailure("item(uint64_t)", "bad value"); } void Deserialiser_TextTree::item(int64_t& v) { eat_ws(); m_is >> v; if( !m_is.good() ) - throw ::std::runtime_error("TODO: Less shit exception, item(int64_t)"); + throw DeserialiseFailure("item(int64_t)", "bad value"); } void Deserialiser_TextTree::item(double& v) { eat_ws(); m_is >> v; if( !m_is.good() ) - throw ::std::runtime_error("TODO: Less shit exception, item(double)"); + throw DeserialiseFailure("item(double)", "bad value"); } void Deserialiser_TextTree::item(::std::string& s) { @@ -223,7 +223,7 @@ void Deserialiser_TextTree::item(::std::string& s) char c = getc(); DEBUG("c = '"<