From ae6072ece6ac02a0d2438d110af90cf6ca2f3f50 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 3 Sep 2014 19:12:59 +0200 Subject: gamma ramps and exception class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libgamma-error.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/libgamma-error.cc') diff --git a/src/libgamma-error.cc b/src/libgamma-error.cc index 86ad1fd..951db22 100644 --- a/src/libgamma-error.cc +++ b/src/libgamma-error.cc @@ -16,7 +16,9 @@ * along with this library. If not, see . */ #include "libgamma-error.hh" + #include +#include namespace libgamma @@ -73,5 +75,52 @@ namespace libgamma return libgamma_value_of_error(cstr); } + + /** + * Constructor. + * + * @param error_code The error code. + */ + LibgammaException::LibgammaException(int error_code) throw() : + error_code(error_code) + { + /* Do nothing. */ + } + + /** + * Destructor. + */ + LibgammaException::~LibgammaException() throw() + { + /* Do nothing. */ + } + + /** + * Get the error as a string. + */ + const char* LibgammaException::what() const throw() + { + if (this->error_code < 0) + return libgamma_name_of_error(this->error_code); + else + return strerror(this->error_code); + } + + + /** + * Create an exception from an error code + * that may come from `errno.h` or be a + * `libgamma` error code. + * + * @param error_code The error code. + * @return The error object. + */ + LibgammaException create_error(int error_code) + { + if (error_code == LIBGAMMA_ERRNO_SET) + error_code = errno; + return LibgammaException(error_code); + } + } -- cgit v1.2.3-70-g09d2