Publishing 2019 R1 content
[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 #define TO_STATUS_NO_RESP(x)\
31 try {x; return OK;\
32 } catch (const InferenceEngine::details::InferenceEngineException & iex) { \
33     return InferenceEngine::DescriptionBuffer(iex.hasStatus() ? iex.getStatus() : GENERAL_ERROR)\
34         << iex.what(); \
35 } catch (const std::exception & ex) {\
36     return InferenceEngine::DescriptionBuffer(GENERAL_ERROR) << ex.what();\
37 } catch (...) {\
38     return InferenceEngine::DescriptionBuffer(UNEXPECTED);\
39 }
40
41 #define NO_EXCEPT_CALL_RETURN_VOID(x)\
42 try { return x; \
43 } catch (const std::exception & ex) {\
44     return;\
45 }
46
47 #define NO_EXCEPT_CALL_RETURN_STATUS(x)\
48 try {return x;\
49 } catch (const InferenceEngine::details::InferenceEngineException & iex) { \
50     return InferenceEngine::DescriptionBuffer(iex.hasStatus() ? iex.getStatus() : GENERAL_ERROR, \
51             resp) << iex.what(); \
52 } catch (const std::exception & ex) {\
53     return InferenceEngine::DescriptionBuffer(GENERAL_ERROR, resp) << ex.what();\
54 } catch (...) {\
55     return InferenceEngine::DescriptionBuffer(UNEXPECTED);\
56 }
57
58 // TODO: replace by hierarchy of exceptions
59 #define PARAMETER_MISMATCH_str std::string("[PARAMETER_MISMATCH] ")
60 #define NETWORK_NOT_LOADED_str std::string("[NETWORK_NOT_LOADED] ")
61 #define NOT_FOUND_str std::string("[NOT_FOUND] ")
62 #define RESULT_NOT_READY_str  std::string("[RESULT_NOT_READY] ")
63 #define INFER_NOT_STARTED_str  std::string("[INFER_NOT_STARTED] ")
64 #define REQUEST_BUSY_str std::string("[REQUEST_BUSY] ")
65 #define NOT_IMPLEMENTED_str std::string("[NOT_IMPLEMENTED] ")
66 #define NOT_ALLOCATED_str std::string("[NOT_ALLOCATED] ")
67
68 }  // namespace InferenceEngine