exception.h (2020-10-27 00:11:00 -0400, (build d99887ae))
Go to the documentation of this file.
1 /*******************************************************
2  * Copyright (c) 2014, 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  * https://arrayfire.com/licenses/BSD-3-Clause
8  ********************************************************/
9 
10 #pragma once
11 
12 #ifdef __cplusplus
13 
14 #include <ostream>
15 #include <af/defines.h>
16 
17 namespace af {
18 
21 class AFAPI exception : public std::exception
22 {
23 private:
24  char m_msg[1024];
25  af_err m_err;
26 public:
27  af_err err() { return m_err; }
28  exception();
30  exception(const char *msg);
31 
34  exception(const char *file, unsigned line, af_err err);
35 
38  exception(const char *msg, const char *file, unsigned line, af_err err);
39 #if AF_API_VERSION >= 33
40  exception(const char *msg, const char *func, const char *file, unsigned line, af_err err);
43 #endif
44  virtual ~exception() throw() {}
46  virtual const char *what() const throw() { return m_msg; }
47 
49  friend inline std::ostream& operator<<(std::ostream &s, const exception &e)
50  { return s << e.what(); }
51 };
52 
53 } // namespace af
54 
55 #endif
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
65 AFAPI void af_get_last_error(char **msg, dim_t *len);
66 
70 AFAPI const char *af_err_to_string(const af_err err);
71 
72 #ifdef __cplusplus
73 }
74 #endif
An ArrayFire exception class.
Definition: exception.h:21
Definition: algorithm.h:14
AFAPI void af_get_last_error(char **msg, dim_t *len)
Returns the last error message that occurred and its error message.
friend std::ostream & operator<<(std::ostream &s, const exception &e)
Writes the exception to a stream.
Definition: exception.h:49
virtual ~exception()
Definition: exception.h:44
af_err err()
Definition: exception.h:27
af_err
Definition: defines.h:71
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:46
long long dim_t
Definition: defines.h:56
#define AFAPI
Definition: defines.h:38
AFAPI const char * af_err_to_string(const af_err err)
Converts the af_err error code to its string representation.