From cc4a2ae6f04f7c14f47c28d94cc7e4b1cf387529 Mon Sep 17 00:00:00 2001 From: Zuo Yihao <46194306+Alive1024@users.noreply.github.com> Date: Fri, 8 Jul 2022 06:22:01 +0800 Subject: [PATCH] Add function_library.h Exception (#8241) * add RuntimeError for checking * add RuntimeError to CHECK_EQ * auto format by CI Co-authored-by: oneflow-ci-bot --- oneflow/core/functional/function_library.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/oneflow/core/functional/function_library.h b/oneflow/core/functional/function_library.h index 570edffb3bc..158fce88e05 100644 --- a/oneflow/core/functional/function_library.h +++ b/oneflow/core/functional/function_library.h @@ -21,6 +21,7 @@ limitations under the License. #include "oneflow/core/functional/packed_functor.h" #include "oneflow/core/common/stride.h" #include "oneflow/core/framework/tensor_methods.h" +#include "oneflow/core/common/throw.h" namespace oneflow { namespace one { @@ -72,7 +73,7 @@ class FunctionLibrary { auto* functors = PackedFuncCreatorMap::FType>::Get(); const auto& it = functors->find(func_name); CHECK_OR_RETURN(it != functors->end()) - << "Functor was not found for \"" << func_name + << Error::RuntimeError() << "Functor was not found for \"" << func_name << "\", please check whether the functor has been registered correctly or not."; return it->second(); } @@ -89,8 +90,9 @@ class FunctionLibrary { void add_functor_creator(const std::string& func_name, Creator creator) { using func_type = typename function_traits::func_type; auto* functors = PackedFuncCreatorMap::FType>::Get(); - CHECK_EQ(functors->count(func_name), 0) - << "The functor with name " << func_name << " has been registered more than once."; + CHECK_OR_THROW(functors->count(func_name) == 0) + << Error::RuntimeError() << "The functor with name " << func_name + << " has been registered more than once."; functors->emplace(func_name, creator); } };