ie_exception_conversion.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file that provides macros to handle no exception methods
7  *
8  * @file ie_exception_conversion.hpp
9  */
10 #pragma once
11 #include <ie_common.h>
12 
13 #define CALL_STATUS_FNC(function, ...) \
14  ResponseDesc resp; \
15  auto res = actual->function(__VA_ARGS__, &resp); \
16  if (res != OK) InferenceEngine::details::extract_exception(res, resp.msg);
17 
18 #define CALL_STATUS_FNC_NO_ARGS(function) \
19  ResponseDesc resp; \
20  auto res = actual->function(&resp); \
21  if (res != OK) InferenceEngine::details::extract_exception(res, resp.msg);
22 
23 #define CALL_FNC(function, ...) \
24  ResponseDesc resp; \
25  auto result = actual->function(__VA_ARGS__, &resp); \
26  if (resp.msg[0] != '\0') { \
27  THROW_IE_EXCEPTION << resp.msg; \
28  } \
29  return result;
30 
31 #define CALL_FNC_REF(function, ...) \
32  ResponseDesc resp; \
33  auto& result = actual->function(__VA_ARGS__, &resp); \
34  if (resp.msg[0] != '\0') { \
35  THROW_IE_EXCEPTION << resp.msg; \
36  } \
37  return result;
38 
39 #define CALL_FNC_NO_ARGS(function) \
40  ResponseDesc resp; \
41  auto result = actual->function(&resp); \
42  if (resp.msg[0] != '\0') { \
43  THROW_IE_EXCEPTION << resp.msg; \
44  } \
45  return result;
46 
47 #define CALL_FNC_NO_ARGS_REF(function) \
48  ResponseDesc resp; \
49  auto& result = actual->function(&resp); \
50  if (resp.msg[0] != '\0') { \
51  THROW_IE_EXCEPTION << resp.msg; \
52  } \
53  return result;
54 
55 namespace InferenceEngine {
56 namespace details {
57 
58 inline void extract_exception(StatusCode status, char* msg) {
59  switch (status) {
60  case NOT_IMPLEMENTED:
61  throw NotImplemented(msg);
62  case NETWORK_NOT_LOADED:
63  throw NetworkNotLoaded(msg);
64  case PARAMETER_MISMATCH:
65  throw ParameterMismatch(msg);
66  case NOT_FOUND:
67  throw NotFound(msg);
68  case OUT_OF_BOUNDS:
69  throw OutOfBounds(msg);
70  case UNEXPECTED:
71  throw Unexpected(msg);
72  case REQUEST_BUSY:
73  throw RequestBusy(msg);
74  case RESULT_NOT_READY:
75  throw ResultNotReady(msg);
76  case NOT_ALLOCATED:
77  throw NotAllocated(msg);
78  case INFER_NOT_STARTED:
79  throw InferNotStarted(msg);
80  case NETWORK_NOT_READ:
81  throw NetworkNotRead(msg);
82  default:
83  THROW_IE_EXCEPTION << msg << InferenceEngine::details::as_status << status;
84  }
85 }
86 
87 } // namespace details
88 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:216
This class represents StatusCode::NETWORK_NOT_READ exception.
Definition: ie_common.h:303
This is a header file with common inference engine definitions.