Update clang-format configuration; reformat source files.
Some checks failed
buildbot/Ascendent (Alpine) Build done.
buildbot/Ascendent (FreeBSD) Build done.

Use std::set_terminate to a function that can handle the engine's
nested exceptions and prints a stacktrace.

Closes #22 - Unify source formatting with clang-format
Closes #19 - Integrate exception handling and backtrace into main
function
This commit is contained in:
S David 2022-09-14 22:38:53 -04:00
parent 183eab166d
commit 080094c474
4 changed files with 29 additions and 42 deletions

View File

@ -7,6 +7,8 @@ UseTab: AlignWithSpaces
ColumnLimit: 81
AccessModifierOffset: -4
BinPackParameters: true
AlignAfterOpenBracket: BlockIndent
AlignOperands: AlignAfterOperator
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: None
ConstructorInitializerIndentWidth: 2

View File

@ -9,7 +9,6 @@
extern "C" {
void noop(void);
}
// clang-format off

View File

@ -7,15 +7,40 @@
* obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <exception>
#include <iostream>
#include "engine/Exception.hpp"
#include "engine/debuginfo.hpp"
void
termination_handler(void)
{
std::cerr << "A fatal error occurred!" << std::endl;
if (auto exception_ptr = std::current_exception()) {
try {
std::rethrow_exception(exception_ptr);
}
catch (const std::exception& ex) {
std::cerr << "Uncaught exception:" << std::endl
<< ex.what() << std::endl;
}
catch (...) {
std::cerr << "Unknown exception" << std::endl;
}
} else {
std::cerr << "std::terminate() was called" << std::endl;
}
std::abort();
}
int
main(int argc, char* argv[])
{
print_cmdline(argc, argv);
std::cout << "Hello World" << std::endl;
std::set_terminate(&termination_handler);
THROW_EXCEPTION("Hello World");
return 0;
}
// clang-format off

View File

@ -18,7 +18,7 @@ class SomeInterface
{
public:
virtual int foo(int) = 0;
virtual int bar(char*)= 0;
virtual int bar(char*) = 0;
};
TEST_CASE("Catch2 works with Fakeit", "[integrity-check]")
@ -40,44 +40,5 @@ TEST_CASE("Catch2 works with Fakeit", "[integrity-check]")
REQUIRE(otheriface.foo(0) == -1);
}
// #region seraization test setup
//struct DataRecord
//{
// id_t id;
// std::string name;
//
// bool operator==(const DataRecord& rhs) const
// {
// return (this->id == rhs.id) && (this->name == rhs.name);
// }
//
// NLOHMANN_DEFINE_TYPE_INTRUSIVE(DataRecord, id, name)
//};
//struct DataRecordCollection
//{
// std::unordered_map<id_t, DataRecord> collection;
//
// NLOHMANN_DEFINE_TYPE_INTRUSIVE(DataRecordCollection, collection)
//
//};
/*TEST_CASE("serizalization works as expected", "[integrity-check]")
{
DataRecord testRecord;
DataRecord expectedResult{ .id = 52, .name = "expected" };
json json_object = expectedResult;
std::string json_string = json_object.dump(4);
// print out the generated json so we can see it when the test runs
std::cout << json_string << std::endl;
auto from_string = json::parse(json_string);
testRecord = from_string.get<DataRecord>();
REQUIRE(expectedResult == testRecord);
}*/
// #endregion
// clang-format off
// vim: set foldmethod=marker foldmarker=#region,#endregion textwidth=80 ts=8 sts=0 sw=8 noexpandtab ft=cpp.doxygen :