A high-performance general-purpose compute library
exception.h
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 * http://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
17namespace af {
18
21class AFAPI exception : public std::exception
22{
23private:
24 char m_msg[1024];
25 af_err m_err;
26public:
27 af_err err() { return m_err; }
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
42 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
58extern "C" {
59#endif
60
65AFAPI void af_get_last_error(char **msg, dim_t *len);
66
70AFAPI const char *af_err_to_string(const af_err err);
71
72#ifdef __cplusplus
73}
74#endif
An ArrayFire exception class.
Definition: exception.h:22
af_err err()
Definition: exception.h:27
exception(const char *msg, const char *file, unsigned line, af_err err)
Creates a new af::exception with a formatted error message for a given an error code,...
virtual ~exception()
Definition: exception.h:44
exception(const char *msg, const char *func, const char *file, unsigned line, af_err err)
Creates a new exception given a message, function name, file name, line number and error code.
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:46
exception(const char *msg)
Creates a new af::exception given a message. The error code is AF_ERR_UNKNOWN.
exception(const char *file, unsigned line, af_err err)
Creates a new exception with a formatted error message for a given file and line number in the source...
friend std::ostream & operator<<(std::ostream &s, const exception &e)
Writes the exception to a stream.
Definition: exception.h:49
long long dim_t
Definition: defines.h:56
af_err
Definition: defines.h:71
#define AFAPI
Definition: defines.h:38
AFAPI void af_get_last_error(char **msg, dim_t *len)
Returns the last error message that occurred and its error message.
AFAPI const char * af_err_to_string(const af_err err)
Converts the af_err error code to its string representation.
Definition: algorithm.h:15