Forge: exception.h Source File

Forge

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

exception.h
Go to the documentation of this file.
1 /*******************************************************
2 * Copyright (c) 2015-2019, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10 #pragma once
11
12 #include <fg/defines.h>
13 #include <iostream>
14 #include <stdexcept>
15
16 static const int MAX_ERR_STR_LEN = 1024;
17
18 namespace fg
19 {
20
21 class FGAPI Error : public std::logic_error
22 {
23 char mFuncName[MAX_ERR_STR_LEN];
24 int mLineNumber;
25 ErrorCode mErrCode;
26
27 Error();
28
29 public:
30
31 Error(const char * const pFuncName, int pLine, const char * const pMessage, ErrorCode pErrCode);
32
33 const char* functionName() const;
34
35 int line() const;
36
37 ErrorCode err() const;
38
39 virtual ~Error() throw();
40
41 friend inline std::ostream& operator<<(std::ostream &s, const Error &e) {
42 return s << "@" << e.functionName() <<":"<< e.line()<<": "<<e.what()<<"("<<e.err()<<")"<<std::endl;
43 }
44 };
45
46 // TODO: Perhaps add a way to return supported types
47 class FGAPI TypeError : public Error
48 {
49 int mArgIndex;
50 char* mErrTypeName;
51
52 TypeError();
53
54 public:
55
56 TypeError(const char * const pFuncName,
57 const int pLine,
58 const int pIndex,
59 const dtype pType);
60
61 const char* typeName() const;
62
63 int argIndex() const;
64
65 ~TypeError() throw();
66 };
67
68 class FGAPI ArgumentError : public Error
69 {
70 int mArgIndex;
71 char* mExpected;
72
73 ArgumentError();
74
75 public:
76 ArgumentError(const char * const pFuncName,
77 const int pLine,
78 const int pIndex,
79 const char * const pExpectString);
80
81 const char* expectedCondition() const;
82
83 int argIndex() const;
84
85 ~ArgumentError() throw();
86 };
87
88 class FGAPI DimensionError : public Error
89 {
90 int mArgIndex;
91 char* mExpected;
92
93 DimensionError();
94
95 public:
96 DimensionError(const char * const pFuncName,
97 const int pLine,
98 const int pIndex,
99 const char * const pExpectString);
100
101 const char* expectedCondition() const;
102
103 int argIndex() const;
104
105 ~DimensionError() throw();
106 };
107
108 }
fg
Definition: CPUCopy.hpp:13
fg::Error::operator<<
friend std::ostream & operator<<(std::ostream &s, const Error &e)
Definition: exception.h:41
fg::Error::functionName
const char * functionName() const
fg::Error::line
int line() const
fg::TypeError
Definition: exception.h:47
FGAPI
#define FGAPI
Definition: defines.h:32
defines.h
fg::dtype
dtype
Definition: defines.h:136
fg::Error
Definition: exception.h:21
MAX_ERR_STR_LEN
static const int MAX_ERR_STR_LEN
Definition: exception.h:16
fg::ErrorCode
ErrorCode
Definition: defines.h:53
fg::DimensionError
Definition: exception.h:88
fg::Error::err
ErrorCode err() const
fg::ArgumentError
Definition: exception.h:68