Exceptions.h 1.12 KB
Newer Older
1
2
3
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H

4
#include <string.h>
5
#include <ostream>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

namespace lima
{

enum Layer {
	Common, Control, Hardware,
};

enum ErrorType {
	InvalidValue, NotSupported, Error,
};


class Exception
{
 public:
22
23
	Exception(Layer layer, ErrorType err_type, std::string err_desc,
		  std::string file_name, std::string funct_name, int line_nr);
24
25


26
	std::string getErrMsg() const;
27

28
29
30
 private:
	Layer m_layer;
	ErrorType m_err_type;
31
32
33
	std::string m_err_desc;
	std::string m_file_name;
	std::string m_funct_name;
34
35
36
	int m_line_nr;
};

37
38
39
40
std::ostream& operator <<(std::ostream& os, Layer layer);
std::ostream& operator <<(std::ostream& os, ErrorType err_type);
std::ostream& operator <<(std::ostream& os, const Exception& e);

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

#define LIMA_EXC(layer, err_type, err_desc) \
	Exception(layer, err_type, err_desc, __FILE__, __FUNCTION__, __LINE__)

#define LIMA_COM_EXC(err_type, err_desc) \
	LIMA_EXC(Common, err_type, err_desc)

#define LIMA_CTL_EXC(err_type, err_desc) \
	LIMA_EXC(Control, err_type, err_desc)

#define LIMA_HW_EXC(err_type, err_desc) \
	LIMA_EXC(Hardware, err_type, err_desc)


} // namespace lima

#endif // EXCEPTIONS_H