Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified throwing macro #5753

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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