Skip to content

Commit

Permalink
Merge pull request #113 from Habbie/observer-update-catch
Browse files Browse the repository at this point in the history
when an observer update throws, log it, do not crash the entire process
  • Loading branch information
Habbie authored Oct 5, 2024
2 parents 7eb2db3 + ce5287e commit fd3622d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/HAEntity.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "HAEntity.hpp"
#include "Backend.hpp"
#include "logger.hpp"

using std::cerr;
using std::endl;
Expand Down Expand Up @@ -86,7 +87,12 @@ void HAEntity::detach(IObserver* _observer)
void HAEntity::notify()
{
for (const auto& obs : observers) {
obs->update();
try {
obs->update();
}
catch (std::exception& e) {
g_log << Logger::LogLevel::Error << "observer threw exception: " << e.what() << endl;
}
}
}

Expand Down

0 comments on commit fd3622d

Please sign in to comment.