Skip to content

Commit

Permalink
buffer: add an exception with an error code
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jdurgin committed Nov 23, 2013
1 parent 30bc0e2 commit eb94b8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb94b8f

Please sign in to comment.