提交 1fd1f06f 编写于 作者: C Chen Weihang 提交者: Tao Luo

Rename paddle throw error macro (#21657)

* rename paddle throw error macro, test=develop

* fix new error use case, test=develop
上级 45702951
...@@ -46,7 +46,8 @@ inline void VisitDataType(PD_DataType type, Visitor visitor) { ...@@ -46,7 +46,8 @@ inline void VisitDataType(PD_DataType type, Visitor visitor) {
_DataType_(VisitDataTypeCallback); _DataType_(VisitDataTypeCallback);
#undef VisitDataTypeCallback #undef VisitDataTypeCallback
PADDLE_THROW_ERROR("Unsupported data type. "); PADDLE_THROW(
paddle::platform::errors::InvalidArgument("Unsupported data type."));
} }
struct PD_ZeroCopyFunctor { struct PD_ZeroCopyFunctor {
......
...@@ -165,9 +165,8 @@ class RecvSaveOpKernel : public framework::OpKernel<T> { ...@@ -165,9 +165,8 @@ class RecvSaveOpKernel : public framework::OpKernel<T> {
auto overwrite = ctx.Attr<bool>("overwrite"); auto overwrite = ctx.Attr<bool>("overwrite");
if (FileExists(filename) && !overwrite) { if (FileExists(filename) && !overwrite) {
PADDLE_THROW_ERROR( PADDLE_THROW(platform::errors::AlreadyExists(
"%s is existed, cannot save to it when overwrite=false", filename, "%s is existed, cannot save to it when overwrite=false", filename));
overwrite);
} }
MkDirRecursively(DirName(filename).c_str()); MkDirRecursively(DirName(filename).c_str());
......
...@@ -223,6 +223,13 @@ inline void throw_on_error(const platform::ErrorSummary& error) { ...@@ -223,6 +223,13 @@ inline void throw_on_error(const platform::ErrorSummary& error) {
#endif #endif
} }
// Note: This Macro can only be used within enforce.h
#define __THROW_ERROR_INTERNAL__(...) \
do { \
throw ::paddle::platform::EnforceNotMet( \
::paddle::string::Sprintf(__VA_ARGS__), __FILE__, __LINE__); \
} while (0)
/** ENFORCE EXCEPTION AND MACROS **/ /** ENFORCE EXCEPTION AND MACROS **/
struct EnforceNotMet : public std::exception { struct EnforceNotMet : public std::exception {
...@@ -251,12 +258,6 @@ struct EnforceNotMet : public std::exception { ...@@ -251,12 +258,6 @@ struct EnforceNotMet : public std::exception {
::paddle::platform::ErrorSummary(__VA_ARGS__), __FILE__, __LINE__); \ ::paddle::platform::ErrorSummary(__VA_ARGS__), __FILE__, __LINE__); \
} while (0) } while (0)
#define PADDLE_THROW_ERROR(...) \
do { \
throw ::paddle::platform::EnforceNotMet( \
::paddle::string::Sprintf(__VA_ARGS__), __FILE__, __LINE__); \
} while (0)
#if defined(__CUDA_ARCH__) #if defined(__CUDA_ARCH__)
// For cuda, the assertions can affect performance and it is therefore // For cuda, the assertions can affect performance and it is therefore
// recommended to disable them in production code // recommended to disable them in production code
...@@ -298,10 +299,11 @@ struct EnforceNotMet : public std::exception { ...@@ -298,10 +299,11 @@ struct EnforceNotMet : public std::exception {
* extra messages is also supported, for example: * extra messages is also supported, for example:
* PADDLE_ENFORCE(a, b, "some simple enforce failed between %d numbers", 2) * PADDLE_ENFORCE(a, b, "some simple enforce failed between %d numbers", 2)
*/ */
#define PADDLE_ENFORCE_NOT_NULL(__VAL, ...) \ #define PADDLE_ENFORCE_NOT_NULL(__VAL, ...) \
do { \ do { \
if (UNLIKELY(nullptr == (__VAL))) { \ if (UNLIKELY(nullptr == (__VAL))) { \
PADDLE_THROW_ERROR( \ __THROW_ERROR_INTERNAL__( \
"%s\n [Hint: " #__VAL " should not be null.]", \ "%s\n [Hint: " #__VAL " should not be null.]", \
::paddle::platform::ErrorSummary(__VA_ARGS__).ToString()); \ ::paddle::platform::ErrorSummary(__VA_ARGS__).ToString()); \
} \ } \
...@@ -323,7 +325,7 @@ struct EnforceNotMet : public std::exception { ...@@ -323,7 +325,7 @@ struct EnforceNotMet : public std::exception {
constexpr bool __kCanToString__ = \ constexpr bool __kCanToString__ = \
::paddle::platform::details::CanToString<__TYPE1__>::kValue && \ ::paddle::platform::details::CanToString<__TYPE1__>::kValue && \
::paddle::platform::details::CanToString<__TYPE2__>::kValue; \ ::paddle::platform::details::CanToString<__TYPE2__>::kValue; \
PADDLE_THROW_ERROR( \ __THROW_ERROR_INTERNAL__( \
"%s\n [Hint: Expected %s " #__CMP \ "%s\n [Hint: Expected %s " #__CMP \
" %s, but received %s " #__INV_CMP " %s.]", \ " %s, but received %s " #__INV_CMP " %s.]", \
::paddle::platform::ErrorSummary(__VA_ARGS__).ToString(), #__VAL1, \ ::paddle::platform::ErrorSummary(__VA_ARGS__).ToString(), #__VAL1, \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册