[arrayfire] 60/84: Add function name to exceptions in internal error classes

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Jan 4 23:22:25 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository arrayfire.

commit 2717d42dba6f41486648d63844906609beb49cdb
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date:   Mon Dec 28 22:38:07 2015 -0500

    Add function name to exceptions in internal error classes
    
    * Errors now generated as function_sign()(file:line): Message
    * TODO Add function name to af::exception class in devel branch for v3.3.0
---
 src/api/c/err_common.cpp          |  52 ++++++++++------
 src/api/c/err_common.hpp          | 126 ++++++++++++++++++++++----------------
 src/backend/cpu/err_cpu.hpp       |   5 +-
 src/backend/cuda/err_cuda.hpp     |   3 +-
 src/backend/defines.hpp           |   6 +-
 src/backend/opencl/err_opencl.hpp |   5 +-
 6 files changed, 118 insertions(+), 79 deletions(-)

diff --git a/src/api/c/err_common.cpp b/src/api/c/err_common.cpp
index 945857e..926639e 100644
--- a/src/api/c/err_common.cpp
+++ b/src/api/c/err_common.cpp
@@ -23,20 +23,24 @@
 using std::string;
 using std::stringstream;
 
-AfError::AfError(const char * const funcName,
+AfError::AfError(const char * const func,
+                 const char * const file,
                  const int line,
                  const char * const message, af_err err)
     : logic_error   (message),
-      functionName  (funcName),
+      functionName  (func),
+      fileName      (file),
       lineNumber(line),
       error(err)
 {}
 
-AfError::AfError(string funcName,
+AfError::AfError(string func,
+                 string file,
                  const int line,
                  string message, af_err err)
     : logic_error   (message),
-      functionName  (funcName),
+      functionName  (func),
+      fileName      (file),
       lineNumber(line),
       error(err)
 {}
@@ -47,6 +51,12 @@ AfError::getFunctionName() const
     return functionName;
 }
 
+const string&
+AfError::getFileName() const
+{
+    return fileName;
+}
+
 int
 AfError::getLine() const
 {
@@ -61,10 +71,11 @@ AfError::getError() const
 
 AfError::~AfError() throw() {}
 
-TypeError::TypeError(const char * const  funcName,
+TypeError::TypeError(const char * const  func,
+                     const char * const file,
                      const int line,
                      const int index, const af_dtype type)
-    : AfError (funcName, line, "Invalid data type", AF_ERR_TYPE),
+    : AfError (func, file, line, "Invalid data type", AF_ERR_TYPE),
       argIndex(index),
       errTypeName(getName(type))
 {}
@@ -79,11 +90,12 @@ int TypeError::getArgIndex() const
     return argIndex;
 }
 
-ArgumentError::ArgumentError(const char * const  funcName,
+ArgumentError::ArgumentError(const char * const  func,
+                             const char * const file,
                              const int line,
                              const int index,
                              const char * const  expectString)
-    : AfError(funcName, line, "Invalid argument", AF_ERR_ARG),
+    : AfError(func, file, line, "Invalid argument", AF_ERR_ARG),
       argIndex(index),
       expected(expectString)
 {
@@ -101,10 +113,11 @@ int ArgumentError::getArgIndex() const
 }
 
 
-SupportError::SupportError(const char * const funcName,
+SupportError::SupportError(const char * const func,
+                           const char * const file,
                            const int line,
                            const char * const back)
-    : AfError(funcName, line, "Unsupported Error", AF_ERR_NOT_SUPPORTED),
+    : AfError(func, file, line, "Unsupported Error", AF_ERR_NOT_SUPPORTED),
       backend(back)
 {}
 
@@ -113,11 +126,12 @@ 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 size", AF_ERR_SIZE),
+DimensionError::DimensionError(const char * const  func,
+                               const char * const file,
+                               const int line,
+                               const int index,
+                               const char * const  expectString)
+    : AfError(func, file, line, "Invalid size", AF_ERR_SIZE),
       argIndex(index),
       expected(expectString)
 {
@@ -198,7 +212,7 @@ af_err processException()
         throw;
     } catch (const DimensionError &ex) {
         ss << "In function " << ex.getFunctionName()
-           << "(" << ex.getLine() << "):\n"
+           << "(" << ex.getFileName() << ":" << ex.getLine() << "):\n"
            << "Invalid dimension for argument " << ex.getArgIndex() << "\n"
            << "Expected: " << ex.getExpectedCondition() << "\n";
 
@@ -206,7 +220,7 @@ af_err processException()
         err = AF_ERR_SIZE;
     } catch (const ArgumentError &ex) {
         ss << "In function " << ex.getFunctionName()
-           << "(" << ex.getLine() << "):\n"
+           << "(" << ex.getFileName() << ":" << ex.getLine() << "):\n"
            << "Invalid argument at index " << ex.getArgIndex() << "\n"
            << "Expected: " << ex.getExpectedCondition() << "\n";
 
@@ -221,14 +235,14 @@ af_err processException()
         err = AF_ERR_NOT_SUPPORTED;
     } catch (const TypeError &ex) {
         ss << "In function " << ex.getFunctionName()
-           << "(" << ex.getLine() << "):\n"
+           << "(" << ex.getFileName() << ":" << ex.getLine() << "):\n"
            << "Invalid type for argument " << ex.getArgIndex() << "\n";
 
         print_error(ss.str());
         err = AF_ERR_TYPE;
     } catch (const AfError &ex) {
         ss << "Error in " << ex.getFunctionName()
-           << "(" << ex.getLine() << "):\n"
+           << "(" << ex.getFileName() << ":" << ex.getLine() << "):\n"
            << ex.what() << "\n";
 
         print_error(ss.str());
diff --git a/src/api/c/err_common.hpp b/src/api/c/err_common.hpp
index 66d2f4a..a4ca57f 100644
--- a/src/api/c/err_common.hpp
+++ b/src/api/c/err_common.hpp
@@ -19,23 +19,29 @@
 class AfError   : public std::logic_error
 {
     std::string functionName;
+    std::string fileName;
     int lineNumber;
     af_err error;
     AfError();
 
 public:
 
-    AfError(const char * const funcName,
+    AfError(const char * const func,
+            const char * const file,
             const int line,
             const char * const message, af_err err);
 
-    AfError(std::string funcName,
+    AfError(std::string func,
+            std::string file,
             const int line,
             std::string message, af_err err);
 
     const std::string&
     getFunctionName() const;
 
+    const std::string&
+    getFileName() const;
+
     int getLine() const;
 
     af_err getError() const;
@@ -52,7 +58,8 @@ class TypeError : public AfError
 
 public:
 
-    TypeError(const char * const  funcName,
+    TypeError(const char * const func,
+              const char * const file,
               const int line,
               const int index,
               const af_dtype type);
@@ -68,14 +75,16 @@ public:
 class ArgumentError : public AfError
 {
     int argIndex;
-    std::string    expected;
+    std::string expected;
     ArgumentError();
 
 public:
-    ArgumentError(const char * const funcName,
-                   const int line,
-                   const int index,
-                   const char * const expectString);
+
+    ArgumentError(const char * const func,
+                  const char * const file,
+                  const int line,
+                  const int index,
+                  const char * const expectString);
 
     const std::string&
     getExpectedCondition() const;
@@ -89,11 +98,16 @@ class SupportError  :   public AfError
 {
     std::string backend;
     SupportError();
+
 public:
-    SupportError(const char * const funcName,
+
+    SupportError(const char * const func,
+                 const char * const file,
                  const int line,
                  const char * const back);
+
     ~SupportError()throw() {}
+
     const std::string&
     getBackendName() const;
 };
@@ -101,11 +115,13 @@ public:
 class DimensionError : public AfError
 {
     int argIndex;
-    std::string    expected;
+    std::string expected;
     DimensionError();
 
 public:
-    DimensionError(const char * const funcName,
+
+    DimensionError(const char * const func,
+                   const char * const file,
                    const int line,
                    const int index,
                    const char * const expectString);
@@ -122,61 +138,67 @@ af_err processException();
 
 void print_error(const std::string &msg);
 
-#define DIM_ASSERT(INDEX, COND) do {                    \
-        if((COND) == false) {                           \
-            throw DimensionError(__AF_FILENAME__, __LINE__,    \
-                                 INDEX, #COND);         \
-        }                                               \
+#define DIM_ASSERT(INDEX, COND) do {                        \
+        if((COND) == false) {                               \
+            throw DimensionError(__PRETTY_FUNCTION__,       \
+                                 __AF_FILENAME__, __LINE__, \
+                                 INDEX, #COND);             \
+        }                                                   \
     } while(0)
 
-#define ARG_ASSERT(INDEX, COND) do {                \
-        if((COND) == false) {                       \
-            throw ArgumentError(__AF_FILENAME__, __LINE__, \
-                                INDEX, #COND);      \
-        }                                           \
+#define ARG_ASSERT(INDEX, COND) do {                        \
+        if((COND) == false) {                               \
+            throw ArgumentError(__PRETTY_FUNCTION__,        \
+                                __AF_FILENAME__, __LINE__,  \
+                                INDEX, #COND);              \
+        }                                                   \
     } while(0)
 
-#define TYPE_ERROR(INDEX, type) do {            \
-        throw TypeError(__AF_FILENAME__, __LINE__,     \
-                        INDEX, type);           \
-    } while(0)                                  \
+#define TYPE_ERROR(INDEX, type) do {                        \
+        throw TypeError(__PRETTY_FUNCTION__,                \
+                        __AF_FILENAME__, __LINE__,          \
+                        INDEX, type);                       \
+    } while(0)                                              \
 
 
-#define AF_ERROR(MSG, ERR_TYPE) do {            \
-        throw AfError(__AF_FILENAME__, __LINE__,       \
-                      MSG, ERR_TYPE);           \
+#define AF_ERROR(MSG, ERR_TYPE) do {                        \
+        throw AfError(__PRETTY_FUNCTION__,                  \
+                      __AF_FILENAME__, __LINE__,            \
+                      MSG, ERR_TYPE);                       \
     } while(0)
 
-#define AF_RETURN_ERROR(MSG, ERR_TYPE) do {     \
-        AfError err(__AF_FILENAME__, __LINE__,  \
-                      MSG, ERR_TYPE);           \
-        std::string str = "Error in "           \
-                        + err,getFunctionName() \
-                        + "(" + ex.getLine()    \
-                        + "):\n"                \
-                        + ex.what() + "\n";     \
-        print_error(str);                       \
-        return ERR_TYPE;                        \
+#define AF_RETURN_ERROR(MSG, ERR_TYPE) do {                 \
+        AfError err(__PRETTY_FUNCTION__,                    \
+                    __AF_FILENAME__, __LINE__,              \
+                    MSG, ERR_TYPE);                         \
+        std::string s = "Error in " + err.getFunctionName() \
+                        + "(" + err.getFileName()           \
+                        + ":" + err.getLine() + "):\n"      \
+                        + err.getError().what() + "\n"      \
+                        ;                                   \
+        print_error(str);                                   \
+        return ERR_TYPE;                                    \
     } while(0)
 
-#define TYPE_ASSERT(COND) do {                  \
-        if ((COND) == false) {                  \
-            AF_ERROR("Type mismatch inputs",    \
-                     AF_ERR_DIFF_TYPE);         \
-        }                                       \
+#define TYPE_ASSERT(COND) do {                              \
+        if ((COND) == false) {                              \
+            AF_ERROR("Type mismatch inputs",                \
+                     AF_ERR_DIFF_TYPE);                     \
+        }                                                   \
     } while(0)
 
-#define AF_ASSERT(COND, MESSAGE)                \
+#define AF_ASSERT(COND, MESSAGE)                            \
     assert(MESSAGE && COND)
 
-#define CATCHALL                                \
-    catch(...) {                                \
-        return processException();              \
+#define CATCHALL                                            \
+    catch(...) {                                            \
+        return processException();                          \
     }
 
-#define AF_CHECK(fn) do {                       \
-        af_err __err = fn;                      \
-        if (__err == AF_SUCCESS) break;         \
-        throw AfError(__AF_FILENAME__, __LINE__,       \
-                      "\n", __err);             \
+#define AF_CHECK(fn) do {                                   \
+        af_err __err = fn;                                  \
+        if (__err == AF_SUCCESS) break;                     \
+        throw AfError(__PRETTY_FUNCTION__,                  \
+                      __AF_FILENAME__, __LINE__,            \
+                      "\n", __err);                         \
     } while(0)
diff --git a/src/backend/cpu/err_cpu.hpp b/src/backend/cpu/err_cpu.hpp
index 86239ed..9e995f7 100644
--- a/src/backend/cpu/err_cpu.hpp
+++ b/src/backend/cpu/err_cpu.hpp
@@ -9,6 +9,7 @@
 
 #include <err_common.hpp>
 
-#define CPU_NOT_SUPPORTED() do {                       \
-        throw SupportError(__AF_FILENAME__, __LINE__, "CPU"); \
+#define CPU_NOT_SUPPORTED() do {                        \
+        throw SupportError(__PRETTY_FUNCTION__,         \
+                __AF_FILENAME__, __LINE__, "CPU");      \
     } while(0)
diff --git a/src/backend/cuda/err_cuda.hpp b/src/backend/cuda/err_cuda.hpp
index 74599f8..a975fb5 100644
--- a/src/backend/cuda/err_cuda.hpp
+++ b/src/backend/cuda/err_cuda.hpp
@@ -13,7 +13,8 @@
 #include <err_common.hpp>
 
 #define CUDA_NOT_SUPPORTED() do {                       \
-        throw SupportError(__AF_FILENAME__, __LINE__, "CUDA"); \
+        throw SupportError(__PRETTY_FUNCTION__,         \
+                __AF_FILENAME__, __LINE__, "CUDA");     \
     } while(0)
 
 #define CUDA_CHECK(fn) do {                                 \
diff --git a/src/backend/defines.hpp b/src/backend/defines.hpp
index c65fe51..7445752 100644
--- a/src/backend/defines.hpp
+++ b/src/backend/defines.hpp
@@ -18,9 +18,9 @@
     #define STATIC_ static
     #define __AF_FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
 #else
-    #ifndef __PRETTY_FUNCTION__
-        #define __PRETTY_FUNCTION__ __func__ // __PRETTY_FUNCTION__ Fallback
-    #endif
+    //#ifndef __PRETTY_FUNCTION__
+    //    #define __PRETTY_FUNCTION__ __func__ // __PRETTY_FUNCTION__ Fallback
+    //#endif
     #define STATIC_ inline
     #define __AF_FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
 #endif
diff --git a/src/backend/opencl/err_opencl.hpp b/src/backend/opencl/err_opencl.hpp
index 3b56ae7..15855f3 100644
--- a/src/backend/opencl/err_opencl.hpp
+++ b/src/backend/opencl/err_opencl.hpp
@@ -14,8 +14,9 @@
 #include <platform.hpp>
 #include <types.hpp>
 
-#define OPENCL_NOT_SUPPORTED() do {                         \
-        throw SupportError(__AF_FILENAME__, __LINE__, "OPENCL");   \
+#define OPENCL_NOT_SUPPORTED() do {                     \
+        throw SupportError(__PRETTY_FUNCTION__,         \
+                __AF_FILENAME__, __LINE__, "OpenCL");   \
     } while(0)
 
 #define CL_TO_AF_ERROR(ERR) do {                                \

-- 
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