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