]> git.localhorst.tv Git - blobs.git/blob - src/app/error.cpp
simple planet render
[blobs.git] / src / app / error.cpp
1 #include "error.hpp"
2
3 #include <alut.h>
4 #include <SDL.h>
5 #include <SDL_net.h>
6 #include <GL/glew.h>
7
8 using std::string;
9 using std::runtime_error;
10
11
12 namespace {
13
14 string sdl_error_append(string msg) {
15         const char *error = SDL_GetError();
16         if (*error != '\0') {
17                 msg += ": ";
18                 msg += error;
19                 SDL_ClearError();
20         }
21         return msg;
22 }
23
24 string net_error_append(string msg) {
25         const char *error = SDLNet_GetError();
26         if (*error != '\0') {
27                 msg += ": ";
28                 msg += error;
29         }
30         return msg;
31 }
32
33 string alut_error_append(ALenum num, string msg) {
34         const char *error = alutGetErrorString(num);
35         if (*error != '\0') {
36                 msg += ": ";
37                 msg += error;
38         }
39         return msg;
40 }
41
42 string error_append(string msg, const char *err) {
43         if (err && *err) {
44                 msg += ": ";
45                 msg += err;
46         }
47         return msg;
48 }
49
50 }
51
52 namespace blobs {
53 namespace app {
54
55 AlutError::AlutError(ALenum num)
56 : runtime_error(alutGetErrorString(num)) {
57 }
58
59 AlutError::AlutError(ALenum num, const string &msg)
60 : runtime_error(alut_error_append(num, msg)) {
61 }
62
63
64 GLError::GLError(const char *msg)
65 : runtime_error(error_append(msg, reinterpret_cast<const char *>(gluErrorString(glGetError())))) {
66 }
67
68
69 NetError::NetError()
70 : runtime_error(SDLNet_GetError()) {
71 }
72
73 NetError::NetError(const string &msg)
74 : runtime_error(net_error_append(msg)) {
75 }
76
77
78 SDLError::SDLError()
79 : runtime_error(SDL_GetError()) {
80 }
81
82 SDLError::SDLError(const string &msg)
83 : runtime_error(sdl_error_append(msg)) {
84 }
85
86 }
87 }