Publishing R3
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / cpp_interfaces / exception2status.hpp
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 /**
7  * \brief Wrappers from c++ function to c-style one
8  * \file cpp2c.hpp
9  */
10 #pragma once
11
12 #include <string>
13 #include "description_buffer.hpp"
14
15 namespace InferenceEngine {
16
17 /**
18  * @brief conversion of c++ exceptioned function call into c-style one
19  */
20 #define TO_STATUS(x)\
21 try {x; return OK;\
22 } catch (const InferenceEngine::details::InferenceEngineException & iex) { \
23     return InferenceEngine::DescriptionBuffer((iex.hasStatus() ? iex.getStatus() : GENERAL_ERROR), \
24             resp) << iex.what(); \
25 } catch (const std::exception & ex) {\
26     return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what();\
27 } catch (...) {\
28     return InferenceEngine::DescriptionBuffer(UNEXPECTED);\
29 }
30
31 #define TO_STATUS_NO_RESP(x)\
32 try {x; return OK;\
33 } catch (const InferenceEngine::details::InferenceEngineException & iex) { \
34     return InferenceEngine::DescriptionBuffer(iex.hasStatus() ? iex.getStatus() : GENERAL_ERROR)\
35         << iex.what(); \
36 } catch (const std::exception & ex) {\
37     return InferenceEngine::DescriptionBuffer(GENERAL_ERROR) << ex.what();\
38 } catch (...) {\
39     return InferenceEngine::DescriptionBuffer(UNEXPECTED);\
40 }
41
42 #define NO_EXCEPT_CALL_RETURN_VOID(x)\
43 try { return x; \
44 } catch (const std::exception & ex) {\
45     return;\
46 }
47
48 #define NO_EXCEPT_CALL_RETURN_STATUS(x)\
49 try {return x;\
50 } catch (const InferenceEngine::details::InferenceEngineException & iex) { \
51     return InferenceEngine::DescriptionBuffer(iex.hasStatus() ? iex.getStatus() : GENERAL_ERROR, \
52             resp) << iex.what(); \
53 } catch (const std::exception & ex) {\
54     return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what();\
55 } catch (...) {\
56     return InferenceEngine::DescriptionBuffer(UNEXPECTED);\
57 }
58
59 // TODO: replace by hierarchy of exceptions
60 #define PARAMETER_MISMATCH_str std::string("[PARAMETER_MISMATCH] ")
61 #define NETWORK_NOT_LOADED_str std::string("[NETWORK_NOT_LOADED] ")
62 #define NOT_FOUND_str std::string("[NOT_FOUND] ")
63 #define RESULT_NOT_READY_str  std::string("[RESULT_NOT_READY] ")
64 #define INFER_NOT_STARTED_str  std::string("[INFER_NOT_STARTED] ")
65 #define REQUEST_BUSY_str std::string("[REQUEST_BUSY] ")
66 #define NOT_IMPLEMENTED_str std::string("[NOT_IMPLEMENTED] ")
67 #define NOT_ALLOCATED_str std::string("[NOT_ALLOCATED] ")
68
69 }  // namespace InferenceEngine