aboutsummaryrefslogtreecommitdiffstats
path: root/src/libgamma-error.cc
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-09-03 19:12:59 +0200
committerMattias Andrée <maandree@operamail.com>2014-09-03 19:12:59 +0200
commitae6072ece6ac02a0d2438d110af90cf6ca2f3f50 (patch)
treeb27c31cfe1cb02cf865e23d639c7c06a234b2f56 /src/libgamma-error.cc
parentlibgamma_group_gid and libgamma_group_name (diff)
downloadlibgammamm-ae6072ece6ac02a0d2438d110af90cf6ca2f3f50.tar.gz
libgammamm-ae6072ece6ac02a0d2438d110af90cf6ca2f3f50.tar.bz2
libgammamm-ae6072ece6ac02a0d2438d110af90cf6ca2f3f50.tar.xz
gamma ramps and exception class
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/libgamma-error.cc')
-rw-r--r--src/libgamma-error.cc49
1 files changed, 49 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
*/
#include "libgamma-error.hh"
+
#include <iostream>
+#include <cstring>
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);
+ }
+
}