-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexception.h
58 lines (44 loc) · 1.21 KB
/
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
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
57
#ifndef _exception_h_
#define _exception_h_
#include <string>
#include <vector>
#include <exception>
#include "util.h"
class Exception : public std::exception {
public:
Exception(const std::string& type, const std::string& msg)
: type_(type), msg_(msg) { }
virtual const char* what() const throw() {
return (type_ + " => " + msg_).c_str();
}
protected:
std::string type_;
std::string msg_;
};
class ValueError : public Exception {
public:
ValueError(const std::string& msg)
: Exception("ValueError", msg) { }
};
class RuntimeError : public Exception {
public:
RuntimeError(const std::string& msg)
: Exception("RuntimeError", msg) { }
};
class IncompatibleShapes : public ValueError {
public:
static std::string helper(const std::string& fn,
std::initializer_list<std::vector<size_t>> l) {
std::stringstream ss;
ss << fn << ": incompatible shapes {";
for (auto& v : l) {
ss << " " << vstr(v);
}
ss << " }";
return ss.str();
}
IncompatibleShapes(const std::string& fn,
std::initializer_list<std::vector<size_t>> shapes)
: ValueError(helper(fn, shapes)) { }
};
#endif // _exception_h_