forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherr_common.cpp
More file actions
190 lines (151 loc) · 4.39 KB
/
err_common.cpp
File metadata and controls
190 lines (151 loc) · 4.39 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <err_common.hpp>
#include <type_util.hpp>
#include <string>
#include <iostream>
#include <sstream>
using std::string;
using std::stringstream;
using std::cerr;
AfError::AfError(const char * const funcName,
const int line,
const char * const message, af_err err)
: logic_error (message),
functionName (funcName),
lineNumber(line),
error(err)
{}
AfError::AfError(string funcName,
const int line,
string message, af_err err)
: logic_error (message),
functionName (funcName),
lineNumber(line),
error(err)
{}
const string&
AfError::getFunctionName() const
{
return functionName;
}
int
AfError::getLine() const
{
return lineNumber;
}
af_err
AfError::getError() const
{
return error;
}
AfError::~AfError() throw() {}
TypeError::TypeError(const char * const funcName,
const int line,
const int index, const af_dtype type)
: AfError (funcName, line, "Invalid data type", AF_ERR_INVALID_TYPE),
argIndex(index),
errTypeName(getName(type))
{}
const string& TypeError::getTypeName() const
{
return errTypeName;
}
int TypeError::getArgIndex() const
{
return argIndex;
}
ArgumentError::ArgumentError(const char * const funcName,
const int line,
const int index,
const char * const expectString)
: AfError(funcName, line, "Invalid argument", AF_ERR_INVALID_ARG),
argIndex(index),
expected(expectString)
{
}
const string& ArgumentError::getExpectedCondition() const
{
return expected;
}
int ArgumentError::getArgIndex() const
{
return argIndex;
}
SupportError::SupportError(const char * const funcName,
const int line,
const char * const back)
: AfError(funcName, line, "Unsupported Error", AF_ERR_NOT_SUPPORTED),
backend(back)
{}
const string& SupportError::getBackendName() const
{
return backend;
}
DimensionError::DimensionError(const char * const funcName,
const int line,
const int index,
const char * const expectString)
: AfError(funcName, line, "Invalid dimension", AF_ERR_SIZE),
argIndex(index),
expected(expectString)
{
}
const string& DimensionError::getExpectedCondition() const
{
return expected;
}
int DimensionError::getArgIndex() const
{
return argIndex;
}
af_err processException()
{
stringstream ss;
af_err err= AF_ERR_INTERNAL;
try {
throw;
} catch (const DimensionError &ex) {
ss << "In function " << ex.getFunctionName()
<< "(" << ex.getLine() << "):\n"
<< "Invalid dimension for argument " << ex.getArgIndex() << "\n"
<< "Expected: " << ex.getExpectedCondition() << "\n";
cerr << ss.str();
err = AF_ERR_SIZE;
} catch (const ArgumentError &ex) {
ss << "In function " << ex.getFunctionName()
<< "(" << ex.getLine() << "):\n"
<< "Invalid argument at index " << ex.getArgIndex() << "\n"
<< "Expected: " << ex.getExpectedCondition() << "\n";
cerr << ss.str();
err = AF_ERR_ARG;
} catch (const SupportError &ex) {
ss << ex.getFunctionName()
<< " not supported for " << ex.getBackendName()
<< " backend\n";
cerr << ss.str();
err = AF_ERR_NOT_SUPPORTED;
} catch (const TypeError &ex) {
ss << "In function " << ex.getFunctionName()
<< "(" << ex.getLine() << "):\n"
<< "Invalid type for argument " << ex.getArgIndex() << "\n";
cerr << ss.str();
err = AF_ERR_INVALID_TYPE;
} catch (const AfError &ex) {
ss << "Error in " << ex.getFunctionName()
<< "(" << ex.getLine() << "):\n"
<< ex.what() << "\n";
cerr << ss.str();
err = ex.getError();
} catch (...) {
cerr << "Unknown error\n";
err = AF_ERR_UNKNOWN;
}
return err;
}