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 #ifndef MXNET_C_API_ERROR_H_
26 #define MXNET_C_API_ERROR_H_
27 
34 #define MX_API_BEGIN() \
35  try { \
36  on_enter_api(__FUNCTION__);
37 #define MX_API_END() \
38  } \
39  catch (const std::exception &_except_) { \
40  on_exit_api(); \
41  return MXAPIHandleException(_except_); \
42  } \
43  on_exit_api(); \
44  return 0; // NOLINT(*)
45 #define MX_API_END_HANDLE_ERROR(Finalize) \
46  } \
47  catch (const std::exception &_except_) { \
48  Finalize; \
49  on_exit_api(); \
50  return MXAPIHandleException(_except_); \
51  } \
52  on_exit_api(); \
53  return 0; // NOLINT(*)
54 
58 void MXAPISetLastError(const char* msg);
64 inline int MXAPIHandleException(const std::exception &e) {
65  MXAPISetLastError(e.what());
66  return -1;
67 }
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: base.h:89
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
Definition: c_api_error.h:64
void on_exit_api()