Skip to content

Commit

Permalink
chore: catch some exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jan 27, 2025
1 parent 5825513 commit b8b618a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/ll/api/Expected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ struct ErrorInfoBase::Impl {
Stacktrace stacktrace;
};
ErrorInfoBase::ErrorInfoBase() noexcept : impl(std::make_unique<Impl>(Stacktrace::current(1))) {}
std::string Error::message() const noexcept {
std::string Error::message() const noexcept try {
if (!mInfo) {
return "success";
}
auto res = mInfo->message();
res += "\nexpected stacktrace:\n";
res += stacktrace_utils::toString(mInfo->impl->stacktrace);
return res;
} catch (...) {
return "unknown";
}

struct ExceptionError : ErrorInfoBase {
Expand All @@ -43,7 +45,9 @@ struct ExceptionError : ErrorInfoBase {
#else
struct ErrorInfoBase::Impl {};
ErrorInfoBase::ErrorInfoBase() noexcept {}
std::string Error::message() const noexcept { return mInfo ? mInfo->message() : "success"; }
std::string Error::message() const noexcept try { return mInfo ? mInfo->message() : "success"; } catch (...) {
return "unknown";
}

struct ExceptionError : ErrorInfoBase {
std::exception_ptr exc;
Expand Down
27 changes: 20 additions & 7 deletions src/ll/core/tweak/MemoryOperators_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,25 @@ namespace ll::memory {
}
class MimallocMemoryAllocator : public ::Bedrock::Memory::IMemoryAllocator {
public:
virtual void* allocate(uint64 size) { return mi_malloc(size != 0 ? size : 1); }
virtual void* allocate(uint64 size) try { return mi_malloc(size != 0 ? size : 1); } catch (...) {
return nullptr;
}

virtual void release(void* ptr) { mi_free(ptr); }
virtual void release(void* ptr) try { mi_free(ptr); } catch (...) {
}

virtual void* alignedAllocate(uint64 size, uint64 alignment) {
virtual void* alignedAllocate(uint64 size, uint64 alignment) try {
return mi_malloc_aligned(size != 0 ? size : 1, alignment);
} catch (...) {
return nullptr;
}

virtual void alignedRelease(void* ptr) { mi_free(ptr); }
virtual void alignedRelease(void* ptr) try { mi_free(ptr); } catch (...) {
}

virtual uint64 getUsableSize(void* ptr) { return mi_usable_size(ptr); }
virtual uint64 getUsableSize(void* ptr) try { return mi_usable_size(ptr); } catch (...) {
return 0;
}

static void miOutput(char const* msg, void* /*arg*/) {
std::string str{msg};
Expand All @@ -62,9 +70,14 @@ class MimallocMemoryAllocator : public ::Bedrock::Memory::IMemoryAllocator {
getLogger().info(str);
}

virtual void logCurrentState() { mi_stats_print_out(miOutput, nullptr); }
virtual void logCurrentState() try { mi_stats_print_out(miOutput, nullptr); } catch (...) {
}

virtual void* _realloc(gsl::not_null<void*> ptr, uint64 newSize) { return mi_realloc(ptr, newSize); }
virtual void* _realloc(gsl::not_null<void*> ptr, uint64 newSize) try {
return mi_realloc(ptr, newSize);
} catch (...) {
return nullptr;
}
};

#ifdef LL_MEMORY_DEBUG
Expand Down

0 comments on commit b8b618a

Please sign in to comment.