-
Notifications
You must be signed in to change notification settings - Fork 0
/
exception.h
29 lines (22 loc) · 918 Bytes
/
exception.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
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
#include <string>
#include <iostream>
using namespace std;
class Exception {
public:
string file;
int line;
string msg;
public:
Exception(const string &iFile, int iLine, const string &iMsg)
: file(iFile), line(iLine), msg(iMsg) { }
};
inline ostream &operator << (ostream &os, const Exception &e) {
return os << "Exception thrown in file \"" << e.file << "\", line \"" << e.line << "\", mesage: " << e.msg;
}
#define THROW(msg) throw Exception(string(__FILE__), __LINE__, string(msg));
#define THROW_IF(cond, msg) if(cond) { throw Exception(string(__FILE__), __LINE__, string(msg)); }
#define THROW_IF_NOT(cond, msg) if(!(cond)) { throw Exception(string(__FILE__), __LINE__, string(msg)); }
#define THROW_IF_NULL(cond, msg) if((cond) == NULL) { throw Exception(string(__FILE__), __LINE__, string(msg)); }
#endif