-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameError.h
56 lines (48 loc) · 1.64 KB
/
gameError.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Programming 2D Games
// Copyright (c) 2011 by:
// Charles Kelly
// gameError.h v1.3
// Error class thrown by game engine.
#ifndef _GAMEERROR_H // Prevent multiple definitions if this
#define _GAMEERROR_H // file is included in more than one place
#define WIN32_LEAN_AND_MEAN
class GameError;
#include <string>
#include <exception>
namespace gameErrorNS
{
// Error codes
// Negative numbers are fatal errors that may require the game to be shutdown.
// Positive numbers are warnings that do not require the game to be shutdown.
const int FATAL_ERROR = -1;
const int WARNING = 1;
}
// Game Error class. Thrown when an error is detected by the game engine.
// Inherits from std::exception
class GameError : public std::exception
{
private:
int errorCode;
std::string message;
public:
// default constructor
GameError() :errorCode(gameErrorNS::FATAL_ERROR), message("Undefined Error in game.") {}
// copy constructor
GameError(const GameError& e) :std::exception(e), errorCode(e.errorCode), message(e.message) {}
// constructor with args
GameError(int code, const std::string &s) :errorCode(code), message(s) {}
// assignment operator
GameError& operator= (const GameError& rhs)
{
std::exception::operator=(rhs);
this->errorCode = rhs.errorCode;
this->message = rhs.message;
}
// destructor
virtual ~GameError() {};
// override what from base class
virtual const char* what() const { return this->getMessage(); }
const char* getMessage() const { return message.c_str(); }
int getErrorCode() const { return errorCode; }
};
#endif