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