From 87ddcea059a763aedd8d4afcdded0d9d3a84942d Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Wed, 23 Apr 2008 17:11:45 +0000 Subject: [PATCH] checking exception on failed statistics reading git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@906 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/webconference/CallStats.cpp | 48 +++++++++++++++++++------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/apps/webconference/CallStats.cpp b/apps/webconference/CallStats.cpp index 12a950ef..c688e658 100644 --- a/apps/webconference/CallStats.cpp +++ b/apps/webconference/CallStats.cpp @@ -26,16 +26,21 @@ void WCCCallStats::save() { if (!filename.length()) return; - std::ofstream ofs(filename.c_str(), - std::ios::out | std::ios::trunc); - if (ofs.good()) { - ofs << total << std::endl << failed << std::endl << seconds; - ofs.close(); - DBG("saved statistics: %u total %u failed %u seconds (%u min)\n", - total, failed, seconds, seconds/60); - } else { - ERROR("opening/writing stats to '%s'\n", - filename.c_str()); + try { + std::ofstream ofs(filename.c_str(), + std::ios::out | std::ios::trunc); + if (ofs.good()) { + ofs << total << std::endl << failed << std::endl << seconds; + ofs.close(); + DBG("saved statistics: %u total %u failed %u seconds (%u min)\n", + total, failed, seconds, seconds/60); + } else { + ERROR("opening/writing stats to '%s'\n", + filename.c_str()); + } + } catch (std::exception& e) { + ERROR("writing stats to '%s': %s\n", + filename.c_str(), e.what()); } } @@ -43,15 +48,20 @@ void WCCCallStats::load() { if (!filename.length()) return; - std::ifstream ifs(filename.c_str(), std::ios::in); - if (ifs.good()) { - ifs >> total >> failed >> seconds; - ifs.close(); - DBG("read statistics: %u total %u failed %u seconds (%u min)\n", - total, failed, seconds, seconds/60); - } else { - ERROR("opening/reading stats from '%s'\n", - filename.c_str()); + try { + std::ifstream ifs(filename.c_str(), std::ios::in); + if (ifs.good()) { + ifs >> total >> failed >> seconds; + ifs.close(); + DBG("read statistics: %u total %u failed %u seconds (%u min)\n", + total, failed, seconds, seconds/60); + } else { + ERROR("opening/reading stats from '%s'\n", + filename.c_str()); + } + } catch (std::exception& e) { + ERROR("opening/reading stats from '%s': %s\n", + filename.c_str(), e.what()); } }