diff --git a/paddle/api/Matrix.cpp b/paddle/api/Matrix.cpp index 0c8d2935a0d6c392c5a7bd6b6af9a8ceaf74f6f7..e5493a381a6f9e3d135c14649a8e1e438494d363 100644 --- a/paddle/api/Matrix.cpp +++ b/paddle/api/Matrix.cpp @@ -53,7 +53,8 @@ Matrix* Matrix::createDense(const std::vector& data, size_t height, } Matrix* Matrix::createDenseFromNumpy(float* data, int dim1, int dim2, - bool copy, bool useGpu) { + bool copy, bool useGpu) + throw (UnsupportError) { if (useGpu) { /// Gpu mode only supports copy=True if (!copy) { diff --git a/paddle/api/Paddle.swig b/paddle/api/Paddle.swig index e723a669f375c52e76b734268a04ae8a49209d83..6a0fbc537d9345f2221ab65d90733f4696be6880 100644 --- a/paddle/api/Paddle.swig +++ b/paddle/api/Paddle.swig @@ -6,17 +6,10 @@ %} %include "exception.i" -%exception{ - try{ - $action - } - catch(UnsupportError &ex ){ - SWIG_exception(SWIG_RuntimeError, ex.what()); - } - catch( ... ){ - SWIG_fail; - } -} +%typemap(throws) UnsupportError %{ + SWIG_exception(SWIG_RuntimeError, $1.what()); + SWIG_fail; +%} %include "std_vector.i" %include "std_pair.i" diff --git a/paddle/api/PaddleAPI.h b/paddle/api/PaddleAPI.h index 807519e739c9b0be9cd7130287d052373b55b923..5688ece44d2d58a2184a9f23d4af26c51c319579 100644 --- a/paddle/api/PaddleAPI.h +++ b/paddle/api/PaddleAPI.h @@ -139,7 +139,8 @@ public: static Matrix* createDenseFromNumpy(float* data, int dim1, int dim2, bool copy = true, - bool useGpu = isUsingGpu()); + bool useGpu = isUsingGpu()) + throw (UnsupportError); /** * Create Cpu Dense Matrix from numpy matrix, dtype=float32 @@ -248,7 +249,8 @@ public: bool useGpu = isUsingGpu()); static Vector* createVectorFromNumpy(float* data, int dim, bool copy = true, - bool useGpu = isUsingGpu()); + bool useGpu = isUsingGpu()) + throw (UnsupportError); /** * Create Cpu Vector from numpy array, which dtype=float32 * @@ -311,7 +313,8 @@ public: bool useGpu = isUsingGpu()); static IVector* createVectorFromNumpy(int* data, int dim, bool copy = true, - bool useGpu = isUsingGpu()); + bool useGpu = isUsingGpu()) + throw (UnsupportError); /** * Create Cpu IVector from numpy array, which dtype=int32 diff --git a/paddle/api/Vector.cpp b/paddle/api/Vector.cpp index 547be27ed560ff64d489cc168493ddb655fa76b4..d44cdefc35bd09e04412b52fb9981947caf89588 100644 --- a/paddle/api/Vector.cpp +++ b/paddle/api/Vector.cpp @@ -40,7 +40,7 @@ IVector* IVector::create(const std::vector& data, bool useGpu) { } IVector* IVector::createVectorFromNumpy(int* data, int dim, bool copy, - bool useGpu) { + bool useGpu) throw (UnsupportError){ if (useGpu) { /// if use gpu only copy=true is supported if (!copy) { @@ -202,7 +202,7 @@ Vector* Vector::createByPaddleVectorPtr(void* ptr) { } Vector* Vector::createVectorFromNumpy(float* data, int dim, bool copy, - bool useGpu) { + bool useGpu) throw (UnsupportError){ if (useGpu) { /// if use gpu only copy=True is supported if (!copy) {