From 0f03078717c37f848b3bc03b8d99e9b46b692af3 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Mon, 22 Mar 2021 10:38:02 -0400 Subject: [PATCH] Improve output. Handle more exceptions in stoi and stof. --- Engine.cpp | 13 ++++--------- UserInterface.cpp | 37 +++++++++++++++++++++++++++++++------ settings.cpp | 17 ++++++++++++++--- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/Engine.cpp b/Engine.cpp index 3c70dc2..eb09fc7 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -72,15 +72,10 @@ void Engine::setEnableTextureInterpolation(bool EnableTextureInterpolation) void Engine::addRecent(std::string path) { - try { - if (!this->hasRecent(path)) { - int count = this->countRecent(); - std::string name = "recent" + std::to_string(count); - this->settings.set(name, path); - } - } - catch (const std::runtime_error& ex) { - std::cerr << ex.what(); + if (!this->hasRecent(path)) { + int count = this->countRecent(); + std::string name = "recent" + std::to_string(count); + this->settings.set(name, path); } } diff --git a/UserInterface.cpp b/UserInterface.cpp index cea92ab..efaf558 100644 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -457,6 +457,9 @@ void UserInterface::handleMenuItemPressed(IGUIContextMenu* menu) m_Engine->getEnableTextureInterpolation() ); break; + default: + cerr << "[UserInterface::handleMenuItemPressed] Unknown caller id: " << id << endl; + break; } } } @@ -807,7 +810,7 @@ void UserInterface::addRecentMenuItem(std::string path, bool addToEngine) u32 newI = this->recentMenu->addItem(path_ws.c_str(), this->uic_file_recent_next); // IGUIContextMenu* menu = this->recentMenu->getSubMenu(newI); this->recentIndices.push_back(newI); - this->uic_file_recent_next += 1; + this->uic_file_recent_next++; /* if (this->m_file_recent_first_idx < 0) { this->m_file_recent_first_idx = menu->getID(); // SIGSEGV crash @@ -828,7 +831,7 @@ void UserInterface::addRecentMenuItems(std::vector paths, bool addT this->addRecentMenuItem(*it, addToEngine); } catch (const std::runtime_error& ex) { - cerr << ex.what(); + cerr << ex.what() << std::endl; break; } } @@ -847,7 +850,16 @@ bool UserInterface::hasRecent(std::string path) } } else { - const std::string msg = "There was no menu for " + std::to_string(*uiIt) + " in hasRecent"; + std::string uiItMsg = std::to_string(*uiIt); + // std::string uiItMsg = "Caller->getID(); + // TODO: switch (ge->EventType) { + // // See http://irrlicht.sourceforge.net/docu/example009.html + // case EGET_MENU_ITEM_SELECTED: + // case EGET_SCROLL_BAR_CHANGED: + // case EGET_COMBO_BOX_CHANGED: + // case EGET_BUTTON_CLICKED: + // switch(callerID) { + // case UIE_PLAYBACKSTARTSTOPBUTTON: + // default: + // cerr << "Unknown button clicked: " << callerID << std::endl; + // default: + // cerr << "Unknown event.GUIEvent.EventType " << ge->EventType << std::endl; + // break; switch (callerID) { case UIE_FILEMENU: + case UIE_RECENTMENU: case UIE_PLAYBACKMENU: case UIE_VIEWMENU: // call handler for all menu related actions @@ -911,7 +937,7 @@ bool UserInterface::OnEvent(const SEvent& event) this->addRecentMenuItem(Utility::toString(path), true); } catch (const std::runtime_error& ex) { - cerr << ex.what(); + cerr << ex.what() << std::endl; break; } } @@ -1012,8 +1038,7 @@ bool UserInterface::OnEvent(const SEvent& event) ); } break; - case UIE_RECENTMENU: - cerr << "called UIE_RECENTMENU unexpectedly for \"" << ge->Caller->getText() << "\"" << endl; + case -1: break; default: // if ((ge->Caller->getID() >= this->m_file_recent_first_idx) diff --git a/settings.cpp b/settings.cpp index b5f8614..7f00f6a 100644 --- a/settings.cpp +++ b/settings.cpp @@ -73,28 +73,39 @@ bool Settings::load(std::string path) else if (signPos != std::string::npos) { std::string name = Utility::trim(line.substr(0, signPos)); std::string value = Utility::trim(line.substr(signPos+1)); + cerr << "parsing name=\"" << name << "\" value=\"" << value << "\"" << std::endl; std::string::size_type iSz; std::string::size_type fSz; int valueI; int valueF; + // See if it is a number (silently degrade to string if not). try { valueI = std::stoi(value, &iSz); } catch (const std::invalid_argument& ex) { + // cerr << "[Settings::load] invalid_argument \"" << value << "\" in stoi: " << ex.what() << std::endl; valueI = 0; iSz = 0; } + catch (const std::exception& ex) { + cerr << "[Settings::load] undefined error in stoi: " << ex.what() << std::endl; + } try { valueF = std::stof(value, &iSz); } catch (const std::invalid_argument& ex) { + // cerr << "[Settings::load] invalid_argument \"" << value << "\" in stof: " << ex.what() << std::endl; valueF = 0.0f; fSz = 0; } + catch (const std::exception& ex) { + cerr << "[Settings::load] undefined error in stof: " << ex.what() << std::endl; + } // ^ radix (3rd param) default is 10 (base-10 number system) - cerr << name << std::endl; - cerr << " valueI length: " << iSz << std::endl; - cerr << " valueF length: " << fSz << std::endl; + // cerr << name << std::endl; + // cerr << " valueI length: " << iSz << std::endl; + // cerr << " valueF length: " << fSz << std::endl; + // Silently degrade (Assume the value is supposed to be a string). if (fSz > iSz) { typeStr = "float"; }