Skip to content

Commit

Permalink
Simplified throwing macro
Browse files Browse the repository at this point in the history
  • Loading branch information
apankratovantonp committed May 24, 2021
1 parent eba2410 commit 5b9f784
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 247 deletions.
219 changes: 56 additions & 163 deletions inference-engine/ie_bridges/c/src/ie_c_api.cpp

Large diffs are not rendered by default.

30 changes: 2 additions & 28 deletions inference-engine/include/details/ie_so_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,6 @@ class SOPointer {
}

protected:
#define CATCH_IE_EXCEPTION(ExceptionType) catch (const InferenceEngine::ExceptionType& e) {throw e;}
#define CATCH_IE_EXCEPTIONS \
CATCH_IE_EXCEPTION(GeneralError) \
CATCH_IE_EXCEPTION(NotImplemented) \
CATCH_IE_EXCEPTION(NetworkNotLoaded) \
CATCH_IE_EXCEPTION(ParameterMismatch) \
CATCH_IE_EXCEPTION(NotFound) \
CATCH_IE_EXCEPTION(OutOfBounds) \
CATCH_IE_EXCEPTION(Unexpected) \
CATCH_IE_EXCEPTION(RequestBusy) \
CATCH_IE_EXCEPTION(ResultNotReady) \
CATCH_IE_EXCEPTION(NotAllocated) \
CATCH_IE_EXCEPTION(InferNotStarted) \
CATCH_IE_EXCEPTION(NetworkNotRead) \
CATCH_IE_EXCEPTION(InferCancelled)

/**
* @brief Implements load of object from library if Release method is presented
*/
Expand All @@ -170,11 +154,7 @@ class SOPointer {
using CreateF = void(std::shared_ptr<T>&);
reinterpret_cast<CreateF*>(create)(_ptr);
}
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) {
IE_THROW() << ex.what();
} catch(...) {
IE_THROW(Unexpected);
}
} catch(...) {details::Rethrow();}
}

/**
Expand All @@ -184,14 +164,8 @@ class SOPointer {
try {
using CreateF = void(std::shared_ptr<T>&);
reinterpret_cast<CreateF*>(_so.get_symbol(SOCreatorTrait<T>::name))(_ptr);
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) {
IE_THROW() << ex.what();
} catch(...) {
IE_THROW(Unexpected);
}
} catch(...) {details::Rethrow();}
}
#undef CATCH_IE_EXCEPTION
#undef CATCH_IE_EXCEPTIONS

/**
* @brief The DLL
Expand Down
6 changes: 6 additions & 0 deletions inference-engine/include/ie_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ INFERENCE_ENGINE_DECLARE_EXCEPTION(InferCancelled, INFER_CANCELLED)

// TODO: Move this section out of public API
namespace details {

/**
* @brief Rethrow a copy of exception. UShould be used in catch blocks
*/
[[noreturn]] INFERENCE_ENGINE_API_CPP(void) Rethrow();

/**
* @brief Tag struct used to throw exception
*/
Expand Down
17 changes: 0 additions & 17 deletions inference-engine/src/inference_engine/cpp/exception2status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,6 @@ namespace InferenceEngine {
return InferenceEngine::DescriptionBuffer(UNEXPECTED); \
}

#define CATCH_IE_EXCEPTION(ExceptionType) catch (const InferenceEngine::ExceptionType& e) {throw e;}

#define CATCH_IE_EXCEPTIONS \
CATCH_IE_EXCEPTION(GeneralError) \
CATCH_IE_EXCEPTION(NotImplemented) \
CATCH_IE_EXCEPTION(NetworkNotLoaded) \
CATCH_IE_EXCEPTION(ParameterMismatch) \
CATCH_IE_EXCEPTION(NotFound) \
CATCH_IE_EXCEPTION(OutOfBounds) \
CATCH_IE_EXCEPTION(Unexpected) \
CATCH_IE_EXCEPTION(RequestBusy) \
CATCH_IE_EXCEPTION(ResultNotReady) \
CATCH_IE_EXCEPTION(NotAllocated) \
CATCH_IE_EXCEPTION(InferNotStarted) \
CATCH_IE_EXCEPTION(NetworkNotRead) \
CATCH_IE_EXCEPTION(InferCancelled)

#define CALL_STATUS_FNC(function, ...) \
if (!actual) IE_THROW() << "Wrapper used was not initialized."; \
ResponseDesc resp; \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
namespace InferenceEngine {

#define EXEC_NET_CALL_STATEMENT(...) \
if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \
if (_impl == nullptr) IE_THROW() << "ExecutableNetwork was not initialized."; \
try { \
__VA_ARGS__; \
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \
IE_THROW() << ex.what(); \
} catch (...) { \
IE_THROW(Unexpected); \
}
} catch(...) {details::Rethrow();}

ExecutableNetwork::ExecutableNetwork(const details::SharedObjectLoader& so,
const IExecutableNetworkInternal::Ptr& impl)
Expand Down
23 changes: 1 addition & 22 deletions inference-engine/src/inference_engine/cpp/ie_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,11 @@

namespace InferenceEngine {

#define CATCH_IE_EXCEPTION(ExceptionType) catch (const InferenceEngine::ExceptionType& e) {throw e;}

#define CATCH_IE_EXCEPTIONS \
CATCH_IE_EXCEPTION(GeneralError) \
CATCH_IE_EXCEPTION(NotImplemented) \
CATCH_IE_EXCEPTION(NetworkNotLoaded) \
CATCH_IE_EXCEPTION(ParameterMismatch) \
CATCH_IE_EXCEPTION(NotFound) \
CATCH_IE_EXCEPTION(OutOfBounds) \
CATCH_IE_EXCEPTION(Unexpected) \
CATCH_IE_EXCEPTION(RequestBusy) \
CATCH_IE_EXCEPTION(ResultNotReady) \
CATCH_IE_EXCEPTION(NotAllocated) \
CATCH_IE_EXCEPTION(InferNotStarted) \
CATCH_IE_EXCEPTION(NetworkNotRead) \
CATCH_IE_EXCEPTION(InferCancelled)

#define INFER_REQ_CALL_STATEMENT(...) \
if (_impl == nullptr) IE_THROW() << "Inference Request is not initialized"; \
try { \
__VA_ARGS__ \
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \
IE_THROW() << ex.what(); \
} catch (...) { \
IE_THROW(Unexpected); \
}
} catch(...) {details::Rethrow();}

InferRequest::InferRequest(const details::SharedObjectLoader& so,
const IInferRequestInternal::Ptr& impl)
Expand Down
6 changes: 1 addition & 5 deletions inference-engine/src/inference_engine/cpp/ie_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
if (!_ptr) IE_THROW() << "Wrapper used in the PLUGIN_CALL_STATEMENT was not initialized."; \
try { \
__VA_ARGS__; \
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \
IE_THROW() << ex.what(); \
} catch (...) { \
IE_THROW(Unexpected); \
}
} catch(...) {details::Rethrow();}

namespace InferenceEngine {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
#include "exception2status.hpp"

#define VARIABLE_CALL_STATEMENT(...) \
if (_impl == nullptr) IE_THROW() << "VariableState was not initialized."; \
if (_impl == nullptr) IE_THROW() << "VariableState was not initialized."; \
try { \
__VA_ARGS__; \
} CATCH_IE_EXCEPTIONS catch (const std::exception& ex) { \
IE_THROW() << ex.what(); \
} catch (...) { \
IE_THROW(Unexpected); \
}
} catch(...) {details::Rethrow();}

namespace InferenceEngine {

Expand Down
21 changes: 21 additions & 0 deletions inference-engine/src/inference_engine/ie_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ std::map<std::string, ngraph::OpSet> Extension::getOpSets() {
return actual->getOpSets();
}
namespace details {

void Rethrow() {
try {
throw;
} catch (const GeneralError& e) {throw e;}
catch (const NotImplemented& e) {throw e;}
catch (const NetworkNotLoaded& e) {throw e;}
catch (const ParameterMismatch& e) {throw e;}
catch (const NotFound& e) {throw e;}
catch (const OutOfBounds& e) {throw e;}
catch (const Unexpected& e) {throw e;}
catch (const RequestBusy& e) {throw e;}
catch (const ResultNotReady& e) {throw e;}
catch (const NotAllocated& e) {throw e;}
catch (const InferNotStarted& e) {throw e;}
catch (const NetworkNotRead& e) {throw e;}
catch (const InferCancelled& e) {throw e;}
catch (const std::exception& e) {IE_THROW() << e.what();}
catch(...) {IE_THROW(Unexpected);}
}

IE_SUPPRESS_DEPRECATED_START

StatusCode InferenceEngineException::getStatus() const {
Expand Down

0 comments on commit 5b9f784

Please sign in to comment.