[arrayfire] 137/284: Improvements to af::exception messages
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.
commit b7af25a1b7a5b61b9ba7a3aacaac084a24867d93
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Thu Dec 31 16:06:15 2015 -0500
Improvements to af::exception messages
* Now prints enum string
* Prints functions
* Prints last error
---
include/af/exception.h | 3 +++
src/api/cpp/error.hpp | 12 +++++++++---
src/api/cpp/exception.cpp | 16 ++++++++++++----
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/include/af/exception.h b/include/af/exception.h
index ee10c5d..a43d26d 100644
--- a/include/af/exception.h
+++ b/include/af/exception.h
@@ -27,6 +27,9 @@ public:
exception(const char *msg);
exception(const char *file, unsigned line, af_err err);
exception(const char *msg, const char *file, unsigned line, af_err err);
+#if AF_API_VERSION >= 33
+ exception(const char *msg, const char *func, const char *file, unsigned line, af_err err);
+#endif
virtual ~exception() throw() {}
virtual const char *what() const throw() { return m_msg; }
friend inline std::ostream& operator<<(std::ostream &s, const exception &e)
diff --git a/src/api/cpp/error.hpp b/src/api/cpp/error.hpp
index 157f819..c888db8 100644
--- a/src/api/cpp/error.hpp
+++ b/src/api/cpp/error.hpp
@@ -8,14 +8,20 @@
********************************************************/
#include <af/exception.h>
+#include <af/device.h>
#include <defines.hpp>
#define AF_THROW(fn) do { \
af_err __err = fn; \
if (__err == AF_SUCCESS) break; \
- throw af::exception(__AF_FILENAME__, __LINE__, __err); \
+ char *msg = NULL; af_get_last_error(&msg, NULL);\
+ af::exception ex(msg, __PRETTY_FUNCTION__, \
+ __AF_FILENAME__, __LINE__, __err); \
+ af_free_host(msg); \
+ throw ex; \
} while(0)
-#define AF_THROW_ERR(__msg, __err) do { \
- throw af::exception(__msg, __AF_FILENAME__, __LINE__, __err); \
+#define AF_THROW_ERR(__msg, __err) do { \
+ throw af::exception(__msg, __PRETTY_FUNCTION__, \
+ __AF_FILENAME__, __LINE__, __err); \
} while(0)
diff --git a/src/api/cpp/exception.cpp b/src/api/cpp/exception.cpp
index 373ae29..f88f98b 100644
--- a/src/api/cpp/exception.cpp
+++ b/src/api/cpp/exception.cpp
@@ -32,8 +32,8 @@ exception::exception(const char *msg): m_err(AF_ERR_UNKNOWN)
exception::exception(const char *file, unsigned line, af_err err): m_err(err)
{
snprintf(m_msg, sizeof(m_msg) - 1,
- "ArrayFire Exception(%d): %s\nIn %s:%u",
- (int)err, af_err_to_string(err), file, line);
+ "ArrayFire Exception (%s:%d):\nIn %s:%u",
+ af_err_to_string(err), (int)err, file, line);
m_msg[sizeof(m_msg)-1] = '\0';
}
@@ -41,11 +41,19 @@ exception::exception(const char *file, unsigned line, af_err err): m_err(err)
exception::exception(const char *msg, const char *file, unsigned line, af_err err): m_err(err)
{
snprintf(m_msg, sizeof(m_msg) - 1,
- "ArrayFire Exception(%d): %s\nIn %s:%u",
- (int)(err), msg, file, line);
+ "ArrayFire Exception (%s:%d):\n%s\nIn %s:%u",
+ af_err_to_string(err), (int)(err), msg, file, line);
m_msg[sizeof(m_msg)-1] = '\0';
}
+exception::exception(const char *msg, const char *func, const char *file, unsigned line, af_err err): m_err(err)
+{
+ snprintf(m_msg, sizeof(m_msg) - 1,
+ "ArrayFire Exception (%s:%d):\n%s\nIn function %s\nIn file %s:%u",
+ af_err_to_string(err), (int)(err), msg, func, file, line);
+
+ m_msg[sizeof(m_msg)-1] = '\0';
+}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list