Skip to content

Commit 168e9a1

Browse files
authored
add code to translate exception ptrs into strings (#88)
1 parent 57c4baa commit 168e9a1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/export_js_module.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <iostream>
22
#include <filesystem>
3+
#include <vector>
4+
#include <string>
35

46
#include <pyjs/export_py_object.hpp>
57
#include <pyjs/convert.hpp>
@@ -90,6 +92,18 @@ namespace pyjs
9092
return std::filesystem::is_directory(std::filesystem::path(p));
9193
}
9294

95+
96+
std::string get_exception_message(int exceptionPtr)
97+
{
98+
auto ptr = reinterpret_cast<std::exception *>(exceptionPtr);
99+
100+
// get traceback
101+
std::vector<std::string> traceback;
102+
103+
return std::string(ptr->what());
104+
}
105+
106+
93107
void export_js_module()
94108
{
95109
// interpreter itself,
@@ -126,6 +140,8 @@ namespace pyjs
126140
{ std::cout << val; }));
127141

128142

143+
em::function("get_exception_message", &get_exception_message);
144+
129145
}
130146

131147
}

0 commit comments

Comments
 (0)