From eb94b8fd52c245bbcf305a0c91462ed0a291bd06 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 21 Oct 2013 08:51:54 -0700 Subject: [PATCH] buffer: add an exception with an error code This allows e.g. raw buffer constructors to provide more specific information about what failed, as well as a useful error string automatically. Signed-off-by: Josh Durgin --- src/common/buffer.cc | 2 ++ src/include/buffer.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 2fdb2cab19152..7ac54390943a5 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -69,6 +69,8 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE return buffer_cached_crc_adjusted.read(); } + buffer::error_code::error_code(int error) : + buffer::malformed_input(cpp_strerror(error).c_str()), code(error) {} class buffer::raw { public: diff --git a/src/include/buffer.h b/src/include/buffer.h index 0b497a7cf38d6..3987f021601cd 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -101,6 +101,10 @@ class buffer { private: char buf[256]; }; + struct error_code : public malformed_input { + explicit error_code(int error); + int code; + }; /// total bytes allocated