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 
28 #include <string>
29 
30 #ifndef MXNET_C_API_ERROR_H_
31 #define MXNET_C_API_ERROR_H_
32 
39 #define MX_API_BEGIN() \
40  try { \
41  on_enter_api(__FUNCTION__);
42 #define MX_API_END() \
43  } \
44  catch (const std::exception& _except_) { \
45  on_exit_api(); \
46  return MXAPIHandleException(_except_); \
47  } \
48  on_exit_api(); \
49  return 0; // NOLINT(*)
50 #define MX_API_END_HANDLE_ERROR(Finalize) \
51  } \
52  catch (const std::exception& _except_) { \
53  Finalize; \
54  on_exit_api(); \
55  return MXAPIHandleException(_except_); \
56  } \
57  on_exit_api(); \
58  return 0; // NOLINT(*)
59 
64 void MXAPISetLastError(const char* msg);
70 int MXAPIHandleException(const std::exception& e);
71 
72 namespace mxnet {
73 extern void on_enter_api(const char* function);
74 extern void on_exit_api();
75 }
76 #endif // MXNET_C_API_ERROR_H_
mxnet
namespace of mxnet
Definition: api_registry.h:33
mxnet::on_enter_api
void on_enter_api(const char *function)
MXAPISetLastError
void MXAPISetLastError(const char *msg)
Set the last error message needed by C API.
mxnet::on_exit_api
void on_exit_api()
MXAPIHandleException
int MXAPIHandleException(const std::exception &e)
handle exception throwed out