attempting to use error management
This commit is contained in:
parent
b091a1a637
commit
dfe17164b6
3 changed files with 17 additions and 4 deletions
|
|
@ -1,4 +1,9 @@
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
Error::Error(std::string location) { object = location; }
|
Error::Error(std::string location) { object = location; }
|
||||||
|
void Error::crash(std::string msg) { throw object + ": " + msg; }
|
||||||
|
void Error::crash(std::string reason, std::string msg) {
|
||||||
|
throw object + ": " + reason + ": " + msg;
|
||||||
|
}
|
||||||
|
void Error::warn(std::string msg) { throw object + ": " + msg; }
|
||||||
|
void Error::log(std::string msg) { throw object + ": " + msg; }
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,11 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Error(std::string location);
|
Error(std::string location);
|
||||||
|
|
||||||
|
// TODO: make the crash break game loop
|
||||||
|
void crash(std::string msg);
|
||||||
|
void crash(std::string reason, std::string msg);
|
||||||
|
void warn(std::string msg);
|
||||||
|
// TODO: write log issues to a file rather than throw
|
||||||
|
void log(std::string msg);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ const char *fragmentShaderSource =
|
||||||
|
|
||||||
// Include error class
|
// Include error class
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
#include <string>
|
|
||||||
// TODO: Remove check that error class was included properly
|
|
||||||
Error error("main");
|
Error error("main");
|
||||||
|
|
||||||
// TODO: Create Error handling class
|
// TODO: Create Error handling class
|
||||||
|
|
@ -33,7 +31,10 @@ Error error("main");
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// Initialise SDL2
|
// Initialise SDL2
|
||||||
// TODO: Check if sdl initialised
|
// TODO: Check if sdl initialised
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
||||||
|
error.crash("Unable to initialise SDL: ", SDL_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Make OpenGL use double buffering (Render game first then shove to output)
|
// Make OpenGL use double buffering (Render game first then shove to output)
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue