feat/108-luajit-lambda #126
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
28
iface/common/exception.cc
Normal 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
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user