Mercurial > hg > piper-cpp
changeset 41:10ac36b7198a
Exception handling in adapter code
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Tue, 23 Aug 2016 11:17:01 +0100 |
parents | 55d69b26d4db |
children | 91f5c92d3bf7 |
files | json/VampJson.h |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/json/VampJson.h Mon Aug 22 17:16:44 2016 +0100 +++ b/json/VampJson.h Tue Aug 23 11:17:01 2016 +0100 @@ -979,6 +979,23 @@ return json11::Json(jo); } + static json11::Json + fromException(const std::exception &e, RRType responseType) { + + json11::Json::object jo; + + if (responseType == RRType::List) jo["type"] = "list"; + else if (responseType == RRType::Load) jo["type"] = "load"; + else if (responseType == RRType::Configure) jo["type"] = "configure"; + else if (responseType == RRType::Process) jo["type"] = "process"; + else if (responseType == RRType::Finish) jo["type"] = "finish"; + else jo["type"] = "invalid"; + + jo["success"] = false; + jo["errorText"] = std::string("exception caught: ") + e.what(); + return json11::Json(jo); + } + private: // go private briefly for a couple of helper functions static void