exception_util.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <map>
18 #include <string>
19 #include <cassert>
23 
24 namespace movidius_ncs_lib
25 {
26 std::map<int, std::string> CODE2STR =
27 {
28  {
29  MVNC_BUSY,
30  "device is busy, retry later"
31  }
32  ,
33  {
34  MVNC_ERROR,
35  "an unexpected error was encontered during the function call"
36  }
37  ,
38  {
39  MVNC_OUT_OF_MEMORY,
40  "the host is out of memory"
41  }
42  ,
43  {
44  MVNC_DEVICE_NOT_FOUND,
45  "there is no device at the given index or name"
46  }
47  ,
48  {
49  MVNC_INVALID_PARAMETERS,
50  "at least one of the given parameters is invalid in the context of the function call"
51  }
52  ,
53  {
54  MVNC_TIMEOUT,
55  "timeout in the communication with the device"
56  }
57  ,
58  {
59  MVNC_MVCMD_NOT_FOUND,
60  "the file named MvNCAPI.mvcmd should be installed in the mvnc direcotry"
61  }
62  ,
63  {
64  MVNC_NO_DATA,
65  "no data to return"
66  }
67  ,
68  {
69  MVNC_GONE,
70  "the graph or device has been closed during the operation"
71  }
72  ,
73  {
74  MVNC_UNSUPPORTED_GRAPH_FILE,
75  "the graph file may have been created with an incompatible prior version of the Toolkit"
76  }
77  ,
78  {
79  MVNC_MYRIAD_ERROR,
80  "an error has been reported by Movidius VPU"
81  }
82 };
83 
85 {
86  assert(MVNC_OK >= code && code >= MVNC_MYRIAD_ERROR);
87 
88  try
89  {
90  const std::string msg = CODE2STR.at(code);
91 
92  if (code == MVNC_BUSY)
93  {
94  throw MvncBusy(msg);
95  }
96 
97  if (code == MVNC_ERROR)
98  {
99  throw MvncError(msg);
100  }
101 
102  if (code == MVNC_OUT_OF_MEMORY)
103  {
104  throw MvncOutOfMemory(msg);
105  }
106 
107  if (code == MVNC_DEVICE_NOT_FOUND)
108  {
109  throw MvncDeviceNotFound(msg);
110  }
111 
112  if (code == MVNC_INVALID_PARAMETERS)
113  {
114  throw MvncInvalidParameters(msg);
115  }
116 
117  if (code == MVNC_TIMEOUT)
118  {
119  throw MvncTimeout(msg);
120  }
121 
122  if (code == MVNC_MVCMD_NOT_FOUND)
123  {
124  throw MvncMvCmdNotFound(msg);
125  }
126 
127  if (code == MVNC_NO_DATA)
128  {
129  throw MvncNoData(msg);
130  }
131 
132  if (code == MVNC_GONE)
133  {
134  throw MvncGone(msg);
135  }
136 
137  if (code == MVNC_UNSUPPORTED_GRAPH_FILE)
138  {
139  throw MvncUnsupportedGraphFile(msg);
140  }
141 
142  if (code == MVNC_MYRIAD_ERROR)
143  {
144  throw MvncMyriadError(msg);
145  }
146  }
147  catch (std::out_of_range& e)
148  {
149  }
150 }
151 } // namespace movidius_ncs_lib
std::map< int, std::string > CODE2STR
static void tryToThrowMvncException(int code)


movidius_ncs_lib
Author(s): Xiaojun Huang
autogenerated on Mon Jun 10 2019 14:11:23