Skip to content

Commit

Permalink
when an observer update throws, log it, do not crash the entire process
Browse files Browse the repository at this point in the history
  • Loading branch information
Habbie committed Sep 4, 2024
1 parent 179bb99 commit 3d88d58
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 3d88d58

Please sign in to comment.