Skip to content

Commit

Permalink
Show GraalVM C API error codes (#664)
Browse files Browse the repository at this point in the history
Show GraalVM C API error codes

Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg authored Oct 18, 2023
1 parent f4d55bd commit b758082
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cpp/src/pypowsybl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ graal_isolate_t* isolate = nullptr;
void init() {
graal_isolatethread_t* thread = nullptr;

if (graal_create_isolate(nullptr, &isolate, &thread) != 0) {
throw std::runtime_error("graal_create_isolate error");
int c = graal_create_isolate(nullptr, &isolate, &thread);
if (c != 0) {
throw std::runtime_error("graal_create_isolate error: " + std::to_string(c));
}
}

Expand All @@ -32,16 +33,20 @@ class GraalVmGuard {

thread_ = graal_get_current_thread(isolate);
if (thread_ == nullptr) {
if (graal_attach_thread(isolate, &thread_) != 0) {
throw std::runtime_error("graal_create_isolate error");
int c = graal_attach_thread(isolate, &thread_);
if (c != 0) {
throw std::runtime_error("graal_attach_thread error: " + std::to_string(c));
}
shouldDetach = true;
}
}

~GraalVmGuard() noexcept(false) {
if (shouldDetach && graal_detach_thread(thread_) != 0) {
throw std::runtime_error("graal_detach_thread error");
if (shouldDetach) {
int c = graal_detach_thread(thread_);
if (c != 0) {
throw std::runtime_error("graal_detach_thread error: " + std::to_string(c));
}
}
}

Expand Down

0 comments on commit b758082

Please sign in to comment.