Skip to content

Commit

Permalink
Add function_library.h Exception (#8241)
Browse files Browse the repository at this point in the history
* add RuntimeError for checking

* add RuntimeError to CHECK_EQ

* auto format by CI

Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
  • Loading branch information
Alive1024 and oneflow-ci-bot authored Jul 7, 2022
1 parent b076be7 commit cc4a2ae
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions oneflow/core/functional/function_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -72,7 +73,7 @@ class FunctionLibrary {
auto* functors = PackedFuncCreatorMap<typename PackedFunctorMaker<R(Args...)>::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();
}
Expand All @@ -89,8 +90,9 @@ class FunctionLibrary {
void add_functor_creator(const std::string& func_name, Creator creator) {
using func_type = typename function_traits<Func>::func_type;
auto* functors = PackedFuncCreatorMap<typename PackedFunctorMaker<func_type>::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);
}
};
Expand Down

0 comments on commit cc4a2ae

Please sign in to comment.