mxnet
c_api_error.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
25 #include <string>
26 
27 #ifndef MXNET_C_API_ERROR_H_
28 #define MXNET_C_API_ERROR_H_
29 
36 #define MX_API_BEGIN() \
37  try { \
38  on_enter_api(__FUNCTION__);
39 #define MX_API_END() \
40  } \
41  catch (const std::exception &_except_) { \
42  on_exit_api(); \
43  return MXAPIHandleException(_except_); \
44  } \
45  on_exit_api(); \
46  return 0; // NOLINT(*)
47 #define MX_API_END_HANDLE_ERROR(Finalize) \
48  } \
49  catch (const std::exception &_except_) { \
50  Finalize; \
51  on_exit_api(); \
52  return MXAPIHandleException(_except_); \
53  } \
54  on_exit_api(); \
55  return 0; // NOLINT(*)
56 
61 void MXAPISetLastError(const char* msg);
67 int MXAPIHandleException(const std::exception &e);
68 
69 namespace mxnet {
70 extern void on_enter_api(const char *function);
71 extern void on_exit_api();
72 }
73 #endif // MXNET_C_API_ERROR_H_
namespace of mxnet
Definition: api_registry.h:33
void on_enter_api(const char *function)
void MXAPISetLastError(const char *msg)
Set the last error message needed by C API.
int MXAPIHandleException(const std::exception &e)
handle exception throwed out
void on_exit_api()