From aab65930bcf52eec62d910afa13cea6b6c42f8f7 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 20 Jun 2022 10:53:45 +0000 Subject: [PATCH] - improved Buffer exceptions git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@1038 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- radio/processor/src/Buffer.hpp | 14 ++++++++------ radio/processor/src/Buffer.tcc | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/radio/processor/src/Buffer.hpp b/radio/processor/src/Buffer.hpp index 2fbdf6c..43ddaba 100644 --- a/radio/processor/src/Buffer.hpp +++ b/radio/processor/src/Buffer.hpp @@ -6,8 +6,10 @@ #include #include +#define EXC_MSG(code) (std::string(__PRETTY_FUNCTION__) + ", line " + std::to_string(__LINE__) + ", code " + std::to_string(code)) + #ifdef PROCESSOR_BUFFER_USE_EXCEPTIONS -#define RETURN_OR_EXCEPT(code) throw Buffer::Exception(code) +#define RETURN_OR_EXCEPT(code) throw Buffer::Exception(EXC_MSG(code)) #else #define RETURN_OR_EXCEPT(code) return code #endif @@ -32,19 +34,19 @@ class Buffer : public IBuffer class Exception : public std::exception { + std::string m_msg; + public: - Exception(Result code) + Exception(std::string msg) : std::exception() - , m_code(code) + , m_msg(msg) { } const char* what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW { - static std::string r = "Return code = " + std::to_string(m_code); - return r.c_str(); + return m_msg.c_str(); } - Result m_code; }; Buffer(size_t capacity=0); diff --git a/radio/processor/src/Buffer.tcc b/radio/processor/src/Buffer.tcc index 75ddafd..c75b529 100644 --- a/radio/processor/src/Buffer.tcc +++ b/radio/processor/src/Buffer.tcc @@ -98,6 +98,9 @@ typename Buffer::Result Buffer::write(const T *pData, size_t len) { if (len > free()) { + printf("len : %u\n", len); + printf("free : %u\n", free()); + printf("capa : %u\n", capacity()); RETURN_OR_EXCEPT(Result::Err_InvalidSize); } @@ -140,7 +143,7 @@ T Buffer::readAt(size_t offset) { if (m_len < (1+offset)) { - throw Buffer::Exception(Result::Err_InvalidSize); + RETURN_OR_EXCEPT(Result::Err_InvalidSize); } size_t i = (m_ri + offset) % m_capacity; T result = bufferActive()[i];