Skip to content

Commit

Permalink
Prevent exceptions from escaping scope_exit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaye committed Dec 22, 2024
1 parent 3d70e1a commit b22222f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion compiler+runtime/src/cpp/jank/util/scope_exit.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#include <fmt/format.h>

#include <jank/util/scope_exit.hpp>
#include <jank/runtime/object.hpp>
#include <jank/runtime/core/to_string.hpp>
#include <jank/native_persistent_string/fmt.hpp>

namespace jank::util
{
Expand All @@ -14,6 +19,19 @@ namespace jank::util

scope_exit::~scope_exit()
{
func();
try
{
func();
}
catch(runtime::object_ptr const o)
{
/* TODO: Panic */
fmt::println(stderr, "Exception caught in scope_exit: {}", runtime::to_string(o));
}
catch(std::exception const &e)
{
/* TODO: Panic */
fmt::println(stderr, "Exception caught in scope_exit: {}", e.what());
}
}
}

0 comments on commit b22222f

Please sign in to comment.