]> git.localhorst.tv Git - tacos.git/blobdiff - src/app/error.cpp
the usual suspects
[tacos.git] / src / app / error.cpp
diff --git a/src/app/error.cpp b/src/app/error.cpp
new file mode 100644 (file)
index 0000000..c22aeb9
--- /dev/null
@@ -0,0 +1,56 @@
+#include "error.hpp"
+
+#include <alut.h>
+#include <SDL.h>
+#include <GL/glew.h>
+
+using std::runtime_error;
+using std::string;
+
+
+namespace {
+
+const char *sdl_error_flush() {
+       const char *err = SDL_GetError();
+       if (err && *err) {
+               SDL_ClearError();
+       }
+       return err;
+}
+
+string error_append(string msg, const char *err) {
+       if (err && *err) {
+               msg += ": ";
+               msg += err;
+       }
+       return msg;
+}
+
+}
+
+namespace tacos {
+
+AlutError::AlutError(const char *msg)
+: runtime_error(error_append(msg, alutGetErrorString(alutGetError()))) {
+
+}
+
+
+GLError::GLError(const char *msg)
+: runtime_error(error_append(msg, reinterpret_cast<const char *>(gluErrorString(glGetError())))) {
+
+}
+
+
+GLCompileError::GLCompileError(const char *msg, const char *log)
+: runtime_error(error_append(msg, reinterpret_cast<const char *>(gluErrorString(glGetError()))) + '\n' + log) {
+
+}
+
+
+SDLError::SDLError(const char *msg)
+: runtime_error(error_append(msg, sdl_error_flush())) {
+
+}
+
+}