Skip to content
This repository was archived by the owner on Sep 21, 2024. It is now read-only.

Commit c02f5be

Browse files
author
septi
committed
Swig: add exception handling
1 parent 150fcff commit c02f5be

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ clean:
1515
# 1. get a proper url go to https://services.odata.org/v4/TripPinServiceRW
1616
# 2. replace the url in the below call
1717
test:
18-
LD_LIBRARY_PATH=${PWD}/odatacpp/output python3.6 codegen_tools.py 'https://services.odata.org/v4/(S(sbe2f21zvvhp33ytwqndereb))/TripPinServiceRW/' TripPin
18+
LD_LIBRARY_PATH=${PWD}/odatacpp/output python3.6m codegen_tools.py 'https://services.odata.org/v4/(S(sbe2f21zvvhp33ytwqndereb))/TripPinServiceRW/' TripPin
1919

2020
## pyhon3.x
2121

@@ -46,5 +46,5 @@ test:
4646
all_swig: odata_client_python.i
4747
swig -python -c++ -Wall -DODATACPP_CLIENT_API -I/usr/include -Iodatacpp/include -o odata_client_python_swig_wrap.cxx $<
4848
$(CXX) odata_client_python_swig_wrap.cxx -o odata_client_python_wrap.o -c -g -fPIC -shared -std=c++11 -fno-strict-aliasing -O2 -I/usr/include/python3.6 -Iodatacpp/include -I/usr/include/openssl -I/usr/include/libxml2
49-
$(CXX) odata_client_python_wrap.o -o _odata_client_python.so -g -shared -Lodatacpp/output -L/usr/lib/x86_64-linux-gnu -lodata-client -lpython3.6 -lcpprest -lboost_system -lssl -lcrypto
49+
$(CXX) odata_client_python_wrap.o -o _odata_client_python.so -g -shared -Lodatacpp/output -L/usr/lib/x86_64-linux-gnu -lodata-client -lpython3.6m -lcpprest -lboost_system -lssl -lcrypto
5050

odata_client_python.i

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
%include <std_vector.i>
2020
%include <std_shared_ptr.i>
2121

22+
%include <exception.i>
23+
2224
%include <pycontainer.swg>
2325

2426
namespace web {
@@ -27,7 +29,6 @@ namespace web {
2729
}
2830
}
2931

30-
3132
SHAREDPTR(odata::edm::edm_named_type)
3233
SHAREDPTR(odata::edm::edm_primitive_type)
3334
SHAREDPTR(odata::edm::edm_property_type)
@@ -113,6 +114,20 @@ namespace odata {
113114
%include "odata/communication/http_communication.h"
114115

115116
%include "odata/client/odata_client_options.h"
117+
118+
%exception odata::client::odata_client::send_data_to_server {
119+
try {
120+
$action
121+
} catch (odata::communication::service_exception &e) {
122+
std::string msg = utility::conversions::scan_string(e.what());
123+
SWIG_exception(SWIG_RuntimeError, msg.c_str());
124+
} catch (std::invalid_argument &e) {
125+
SWIG_exception(SWIG_AttributeError, e.what());
126+
} catch (std::exception &e) {
127+
SWIG_exception(SWIG_RuntimeError, e.what());
128+
}
129+
}
130+
116131
%include "odata/client/odata_client.h"
117132

118133
%extend odata::edm::edm_entity_container {
@@ -186,10 +201,21 @@ namespace pplx {
186201
template<class _ReturnType>
187202
class task {
188203
public:
189-
_ReturnType get() const throw(odata::communication::service_exception);
204+
_ReturnType get() const;
190205
};
191206
}
192207

208+
%exception pplx::task::get {
209+
try {
210+
$action
211+
} catch (odata::communication::service_exception &e) {
212+
std::string msg = utility::conversions::scan_string(e.what());
213+
SWIG_exception(SWIG_RuntimeError, msg.c_str());
214+
} catch (std::exception &e) {
215+
SWIG_exception(SWIG_RuntimeError, e.what());
216+
}
217+
}
218+
193219
%template(task_edm_model) pplx::task< std::shared_ptr< ::odata::edm::edm_model > >;
194220
%template(task_odata_entity_values) pplx::task< std::vector< std::shared_ptr< ::odata::core::odata_entity_value > > >;
195221
%template(task_odata_values) pplx::task< std::vector< std::shared_ptr< ::odata::core::odata_value > > >;

0 commit comments

Comments
 (0)