Fix potential bugs: improve exception handling, destructors, and cache management #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses several potential bugs and improves code robustness in the design patterns implementation:
Issues Fixed
1. Improper Exception Usage
Replaced deprecated
std::exception()
with more specificstd::runtime_error
with descriptive messages:This affects 6 locations across
factory.h
andmemoize.h
, providing better error diagnostics.2. Destructors Throwing Exceptions
Fixed destructors in
factory_registrator
andmemoize_registrator
that could throw exceptions, violating C++ best practices:3. Inconsistent Cache Management
Improved cache consistency in the memoize class by ensuring both
_map_cache
(weak_ptr) and_map_cache_shared
(shared_ptr) are managed together:4. Thread Safety Documentation
Added explicit warnings about thread safety requirements, as these classes use mutable containers without synchronization.
5. Build Configuration
Updated
.gitignore
to properly excludenode_modules/
and build artifacts.Testing
The changes maintain backward compatibility and don't affect the public API. All existing tests should continue to pass as the fixes address potential runtime issues and improve error handling without changing functionality.
These improvements make the codebase more robust, follow C++ best practices, and provide better debugging information when issues occur.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.