From b559f025e96e548e5da3100d199917dac50ceb7f Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 25 May 2022 11:30:44 +0200 Subject: [PATCH] Report error to wren if an exception is thrown --- include/wrenpp/vm_fun.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/wrenpp/vm_fun.hpp b/include/wrenpp/vm_fun.hpp index 98768a6..e783019 100644 --- a/include/wrenpp/vm_fun.hpp +++ b/include/wrenpp/vm_fun.hpp @@ -220,8 +220,15 @@ namespace wren { inline T* make_wren_object(VM& vm, ModuleAndName mn, Args&&... args) { variable(vm, mn, 0); void* const mem = vm.set_slot_new_foreign(0, 0, sizeof(T)); - T* const obj = new(mem) T{std::forward(args)...}; - return obj; + try { + T* const obj = new(mem) T{std::forward(args)...}; + return obj; + } + catch (const std::runtime_error& err) { + set(vm, 1, err.what()); + vm.abort_fiber(1); + return nullptr; + } } #if defined(WRENPP_WITH_NAME_GUESSING)