-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexcept.h
More file actions
65 lines (55 loc) · 1.87 KB
/
except.h
File metadata and controls
65 lines (55 loc) · 1.87 KB
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
58
59
60
61
62
63
64
65
#ifndef DYNET_EXCEPT_H_
#define DYNET_EXCEPT_H_
#include <stdexcept>
#include <sstream>
namespace dynet {
// if DYNET exhausts its memory pool
class out_of_memory : public std::runtime_error {
public:
out_of_memory(const std::string& what_arg) : runtime_error(what_arg) {}
};
// this error occurs when some logic is
// attempted to execut on a CUDA backend but the
// logic has not been implemented.
class cuda_not_implemented : public std::logic_error {
public:
cuda_not_implemented(const std::string& what_arg) : logic_error(what_arg) {}
};
// this is thrown when cuda returns an error (bad arguments, memory, state, etc)
class cuda_exception : public std::runtime_error {
public:
cuda_exception(const std::string& what_arg) : runtime_error(what_arg) {}
};
} // namespace dynet
#ifdef DYNET_SKIP_ARG_CHECK
#define DYNET_INVALID_ARG(msg)
#define DYNET_ARG_CHECK(cond, msg)
#else
#define DYNET_INVALID_ARG(msg) do { \
std::ostringstream oss; \
oss << msg; \
throw std::invalid_argument(oss.str()); \
} while (0);
#define DYNET_ARG_CHECK(cond, msg) do { \
if (!(cond)) { \
std::ostringstream oss; \
oss << msg; \
throw std::invalid_argument(oss.str()); } \
} while (0);
#endif
#ifdef DYNET_DO_ASSERT
#define DYNET_ASSERT(expr, msg) do { \
if(!(expr)) { \
std::ostringstream oss; \
oss << msg; \
throw std::runtime_error(oss.str()); } \
} while (0);
#else
#define DYNET_ASSERT(expr, msg)
#endif
#define DYNET_RUNTIME_ERR(msg) do { \
std::ostringstream oss; \
oss << msg; \
throw std::runtime_error(oss.str()); } \
while (0);
#endif