feat/108-luajit-lambda #126

Merged
falsycat merged 18 commits from feat/108-luajit-lambda into main 2023-08-06 00:38:23 +00:00
4 changed files with 43 additions and 4 deletions
Showing only changes of commit 4fd6b17936 - Show all commits

View File

@ -36,8 +36,8 @@ class ContextFixture : public ::testing::TestWithParam<Context::Kind> {
task(param_);
} catch (const Exception& e) {
std::cerr
<< "unexpected exception while async task execution: " << e.what()
<< std::endl;
<< "unexpected exception while async task execution:\n"
<< e << std::endl;
std::abort();
}
}
@ -66,8 +66,8 @@ class ContextFixture : public ::testing::TestWithParam<Context::Kind> {
task(param_);
} catch (const Exception& e) {
std::cerr
<< "unexpected exception while sync task execution: " << e.what()
<< std::endl;
<< "unexpected exception while sync task execution:\n"
<< e << std::endl;
std::abort();
}
}

View File

@ -6,10 +6,12 @@ target_link_libraries(nf7_iface
)
target_sources(nf7_iface
PRIVATE
common/exception.cc
version.cc
PUBLIC
common/dealer.hh
common/container.hh
common/exception.hh
common/future.hh
common/observer.hh
common/task.hh

28
iface/common/exception.cc Normal file
View File

@ -0,0 +1,28 @@
// No copyright
#include "iface/common/exception.hh"
namespace nf7 {
std::ostream& operator<<(std::ostream& st, const Exception& e) {
auto idx = uint32_t {0};
auto ptr = &e;
while (true) {
const auto& loc = ptr->location();
st << idx << ": " << ptr->what() << "\n";
st << " " << loc.file_name() << ":" << loc.line() << "\n";
st << " " << loc.function_name() << "\n";
try {
ptr->RethrowNestedIf();
break;
} catch (const Exception& e2) {
ptr = &e2;
++idx;
} catch (const std::exception& e2) {
st << idx << ": " << e2.what() << "\n";
break;
}
}
return st;
}
} // namespace nf7

View File

@ -2,6 +2,7 @@
#pragma once
#include <exception>
#include <ostream>
#include <source_location>
namespace nf7 {
@ -14,6 +15,12 @@ class Exception : public std::exception, std::nested_exception {
std::source_location location = std::source_location::current()) :
what_(what), location_(location) { }
void RethrowNestedIf() const {
if (auto ptr = nested_ptr()) {
std::rethrow_exception(ptr);
}
}
const char* what() const noexcept override { return what_; }
const std::source_location& location() const noexcept { return location_; }
@ -22,4 +29,6 @@ class Exception : public std::exception, std::nested_exception {
std::source_location location_;
};
std::ostream& operator<<(std::ostream&, const Exception& e);
} // namespace nf7