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