Skip to content

Commit 199b681

Browse files
committed
initial code for error handling
1 parent a2f9fe7 commit 199b681

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ run-example: target/tikv-example
2121
RUST_LOG=debug $(cur_makefile_path)/target/tikv-example
2222

2323
target/tikv-example: target/debug/libtikv_client.a example/main.cpp
24-
c++ $(cur_makefile_path)/example/main.cpp -o $(cur_makefile_path)/target/tikv-example -std=c++17 -g -I$(cur_makefile_path)/include -L$(cur_makefile_path)/target/debug -ltikv_client -lpthread -ldl -lssl -lcrypto
24+
c++ $(cur_makefile_path)/example/main.cpp -o $(cur_makefile_path)/target/tikv-example -std=c++17 -g -I$(cur_makefile_path)/include -L$(cur_makefile_path)/target/debug -ltikv_client -lpthread -ldl -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include -lssl -lcrypto
2525

2626

2727
target/tikv_client_glue.cc: src/lib.rs

include/tikv_client_glue.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,29 @@ template <typename T>
182182
Box<T>::Box(uninit) noexcept {}
183183
#endif // CXXBRIDGE1_RUST_BOX
184184

185+
class Exception : public std::exception {
186+
public:
187+
Exception(int errorCode, const std::string &message) : errorCode(erroCode), message(message);
188+
virtual ~Exception() = default;
189+
const char* what() const {
190+
return this->message.c_str();
191+
};
192+
193+
private:
194+
int errorCode;
195+
std::string m_message;
196+
};
197+
198+
template <typename Try>
199+
static void trycatch(Try &&func) noexcept try {
200+
func();
201+
} catch (const std::exception &e) {
202+
start error_message = e.what();
203+
int error_code = 0;
204+
205+
throw Exception(error_code, error_message);
206+
}
207+
185208
#ifndef CXXBRIDGE1_RUST_BITCOPY
186209
#define CXXBRIDGE1_RUST_BITCOPY
187210
struct unsafe_bitcopy_t final {

0 commit comments

Comments
 (0)