Exceptions.cpp 1.16 KB
Newer Older
1
2
#include "Exceptions.h"

3
4
#include <sstream>

5
using namespace lima;
6
using namespace std;
7

8
9
Exception::Exception(Layer layer, ErrorType err_type, string err_desc,
		     string file_name, string funct_name, int line_nr)
10
11
12
13
	: m_layer(layer), m_err_type(err_type), m_err_desc(err_desc),
	  m_file_name(file_name), m_funct_name(funct_name), m_line_nr(line_nr)
{
}
14
15


16
string Exception::getErrMsg() const
17
18
19
20
21
22
23
24
25
{
	ostringstream os;
	os << m_layer << ": " 
	   << m_funct_name  << "(" << m_file_name << ", " 
	   << m_line_nr << "): " 
	   << m_err_type << ": " << m_err_desc;
	return os.str();
}

26
ostream& lima::operator <<(ostream& os, Layer layer)
27
{
28
29
30
31
32
33
34
	string name = "Unknown";
	switch (layer) {
	case Common:	name = "Common";	break;
	case Control:	name = "Control";	break;
	case Hardware:	name = "Hardware";	break;
	}
	return os << name;
35
}
36

37
ostream& lima::operator <<(ostream& os, ErrorType err_type)
38
39
40
41
42
43
44
45
46
47
{
	string name = "Unknown";
	switch (err_type) {
	case InvalidValue:	name = "InvalidValue";	break;
	case NotSupported:	name = "NotSupported";	break;
	case Error:		name = "Error";		break;
	}
	return os << name;
}

48
ostream& lima::operator <<(ostream& os, const Exception& e)
49
50
51
52
{
	return os << e.getErrMsg();
}