Attempt to put some order to the single general (that differs only by messages) and typed exception, on the example of NOT_IMPLEMENTED (#3537)

NOT_IMPLEMENTED status code correctly translates to the NonImplemented exception (and handled as the correspondingly typed exception)
This commit is contained in:
Maxim Shevtsov 2020-12-14 10:27:29 +03:00 committed by GitHub
parent 77ecd7e17c
commit ee8e9a9e8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 77 deletions

View File

@ -20,7 +20,7 @@
/**
* @def THROW_IE_EXCEPTION
* @brief A macro used to throw the exception with a notable description
* @brief A macro used to throw general exception with a description
*/
#define THROW_IE_EXCEPTION throw InferenceEngine::details::InferenceEngineException(__FILE__, __LINE__)

View File

@ -480,8 +480,7 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(std::istream&
bool loaded = false;
try {
executableNetwork = _heteroPlugin->GetCore()->ImportNetwork(heteroModel, deviceName, loadConfig);
} catch(InferenceEngine::details::InferenceEngineException& ie_ex) {
if (std::string::npos != std::string{ie_ex.what()}.find(NOT_IMPLEMENTED_str)) {
} catch(const InferenceEngine::NotImplemented&) {
// read XML content
std::string xmlString;
std::getline(heteroModel, xmlString);
@ -517,9 +516,6 @@ HeteroExecutableNetwork::HeteroExecutableNetwork(std::istream&
}
executableNetwork = _heteroPlugin->GetCore()->LoadNetwork(cnnnetwork, deviceName, loadConfig);
loaded = true;
} else {
throw;
}
}
for (auto&& input : executableNetwork.GetInputsInfo()) {
@ -597,11 +593,10 @@ void HeteroExecutableNetwork::ExportImpl(std::ostream& heteroModel) {
for (auto&& subnetwork : networks) {
try {
subnetwork._network.Export(heteroModel);
} catch (InferenceEngine::details::InferenceEngineException& ie_ex) {
if (std::string::npos != std::string{ie_ex.what()}.find(NOT_IMPLEMENTED_str)) {
} catch (const InferenceEngine::NotImplemented&) {
// TODO: enable once serialization to IR v10 is implemented
#if 1
THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str
THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED)
<< "Device " << subnetwork._device << " does not implement Export method";
#else
pugi::xml_document doc;
@ -612,9 +607,6 @@ void HeteroExecutableNetwork::ExportImpl(std::ostream& heteroModel) {
heteroModel.write(reinterpret_cast<char*>(&dataSize), sizeof(dataSize));
InferenceEngine::Serialization::SerializeBlobs(heteroModel, subnet);
#endif
} else {
throw;
}
}
}
}

View File

@ -171,9 +171,8 @@ RemoteContext::Ptr MultiDeviceExecutableNetwork::GetContext() const {
} catch (const NotImplemented& ex) {
}
}
THROW_IE_EXCEPTION << InferenceEngine::details::as_status << StatusCode::NOT_IMPLEMENTED
<< NOT_IMPLEMENTED_str << "None of the devices in the MULTI has an associated remote context."
<< "Current list of devices allowed via the DEVICE_PRIORITIES config: " << devices_names;
THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED) << "None of the devices in the MULTI has an associated remote context."
<< " Current list of devices allowed via the DEVICE_PRIORITIES config: " << devices_names;
}
InferenceEngine::InferRequestInternal::Ptr MultiDeviceExecutableNetwork::CreateInferRequestImpl(InferenceEngine::InputsDataMap networkInputs,
@ -210,8 +209,7 @@ IInferRequest::Ptr MultiDeviceExecutableNetwork::CreateInferRequest() {
void MultiDeviceExecutableNetwork::SetConfig(const std::map<std::string, InferenceEngine::Parameter> &config) {
auto priorities = config.find(MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES);
if (priorities == config.end() || config.size() > 1) {
THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str <<
"The only config supported for the Network's SetConfig is MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES";
THROW_IE_EXCEPTION << "The only config supported for the Network's SetConfig is MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES";
} else {
auto multiPlugin = std::dynamic_pointer_cast<MultiDeviceInferencePlugin>(this->_plugin);
assert(multiPlugin != nullptr);
@ -220,7 +218,7 @@ void MultiDeviceExecutableNetwork::SetConfig(const std::map<std::string, Inferen
if (std::any_of(metaDevices.begin(), metaDevices.end(), [](const DeviceInformation& kvp) {
return kvp.numRequestsPerDevices != -1;
})) {
THROW_IE_EXCEPTION << NOT_IMPLEMENTED_str << "You can only change device priorities but not number of requests"
THROW_IE_EXCEPTION << "You can only change device priorities but not number of requests"
<<" with the Network's SetConfig(MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES!";
}

View File

@ -12,6 +12,13 @@
#include "description_buffer.hpp"
/**
* @def THROW_IE_EXCEPTION_WITH_STATUS
* @brief Throws an exception along with the status (which is eventually converted to the typed exception)
*/
#define THROW_IE_EXCEPTION_WITH_STATUS(__status) THROW_IE_EXCEPTION << \
InferenceEngine::details::as_status << InferenceEngine::StatusCode::__status << __status##_str
namespace InferenceEngine {
/**
@ -86,6 +93,18 @@ namespace InferenceEngine {
*/
#define NOT_FOUND_str std::string("[NOT_FOUND] ")
/**
* @def UNEXPECTED_str
* @brief Defines the `unexpected` message
*/
#define UNEXPECTED_str std::string("[UNEXPECTED] ")
/**
* @def GENERAL_ERROR_str
* @brief Defines the `general error` message
*/
#define GENERAL_ERROR_str std::string("[GENERAL ERROR] ")
/**
* @def RESULT_NOT_READY_str
* @brief Defines the `result not ready` message

View File

@ -64,7 +64,7 @@ public:
void Export(const std::string& modelFileName) override {
(void)modelFileName;
THROW_IE_EXCEPTION << InferenceEngine::details::as_status << StatusCode::NOT_IMPLEMENTED << NOT_IMPLEMENTED_str;
THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
}
void Export(std::ostream& networkModel) override {
@ -76,7 +76,7 @@ public:
}
CNNNetwork GetExecGraphInfo() override {
THROW_IE_EXCEPTION << InferenceEngine::details::as_status << StatusCode::NOT_IMPLEMENTED << NOT_IMPLEMENTED_str;
THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
}
/**
@ -89,7 +89,7 @@ public:
}
std::vector<IVariableStateInternal::Ptr> QueryState() override {
THROW_IE_EXCEPTION << InferenceEngine::details::as_status << StatusCode::NOT_IMPLEMENTED << NOT_IMPLEMENTED_str;
THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
}
void SetConfig(const std::map<std::string, Parameter>& config) override {
@ -107,11 +107,11 @@ public:
Parameter GetMetric(const std::string& name) const override {
(void)name;
THROW_IE_EXCEPTION << InferenceEngine::details::as_status << StatusCode::NOT_IMPLEMENTED << NOT_IMPLEMENTED_str;
THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
}
RemoteContext::Ptr GetContext() const override {
THROW_IE_EXCEPTION << InferenceEngine::details::as_status << StatusCode::NOT_IMPLEMENTED << NOT_IMPLEMENTED_str;
THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
}
protected:
@ -123,7 +123,7 @@ protected:
*/
virtual void ExportImpl(std::ostream& networkModel) {
(void)networkModel;
THROW_IE_EXCEPTION << InferenceEngine::details::as_status << StatusCode::NOT_IMPLEMENTED << NOT_IMPLEMENTED_str;
THROW_IE_EXCEPTION_WITH_STATUS(NOT_IMPLEMENTED);
}
InferenceEngine::InputsDataMap _networkInputs; //!< Holds infromation about network inputs info

View File

@ -61,17 +61,7 @@ namespace BehaviorTestsDefinitions {
{ \
try { \
__VA_ARGS__; \
} catch(InferenceEngine::details::InferenceEngineException& ieException) { \
auto notImplementedExceptionIsThrown = \
std::string::npos != std::string {ieException.what()} \
.find(NOT_IMPLEMENTED_str); \
if (notImplementedExceptionIsThrown) { \
GTEST_SKIP(); \
} else { \
FAIL() << "thrown from expression: " # __VA_ARGS__ << std::endl \
<< "what: " << ieException.what(); \
} \
} catch (const InferenceEngine::NotImplemented& ex) { \
} catch (const InferenceEngine::NotImplemented&) { \
GTEST_SKIP(); \
} \
}