aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-12-08 20:09:27 +0200
committerRiccardo Spagni <ric@spagni.net>2015-12-08 20:09:30 +0200
commitcab6f1239e60a799b4b3305127bce997c2094aa3 (patch)
tree1e350374c349e70b08ed13604213887775423d7f
parentMerge pull request #520 (diff)
parentconsole_handler: catch exception inside the input loop (diff)
downloadmonero-cab6f1239e60a799b4b3305127bce997c2094aa3.tar.xz
Merge pull request #521
4cede18 console_handler: catch exception inside the input loop (moneromooo-monero)
-rw-r--r--contrib/epee/include/console_handler.h69
1 files changed, 37 insertions, 32 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index c6e7c857d..685f0cc7b 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -268,52 +268,57 @@ namespace epee
template<typename t_cmd_handler>
bool run(const std::string& prompt, const std::string& usage, const t_cmd_handler& cmd_handler, std::function<void(void)> exit_handler)
{
- TRY_ENTRY();
bool continue_handle = true;
m_prompt = prompt;
while(continue_handle)
{
- if (!m_running)
+ try
{
- break;
- }
- print_prompt();
+ if (!m_running)
+ {
+ break;
+ }
+ print_prompt();
- std::string command;
- bool get_line_ret = m_stdin_reader.get_line(command);
- if (!m_running || m_stdin_reader.eos())
- {
- break;
- }
- if (!get_line_ret)
- {
- LOG_PRINT("Failed to read line.", LOG_LEVEL_0);
- }
- string_tools::trim(command);
+ std::string command;
+ bool get_line_ret = m_stdin_reader.get_line(command);
+ if (!m_running || m_stdin_reader.eos())
+ {
+ break;
+ }
+ if (!get_line_ret)
+ {
+ LOG_PRINT("Failed to read line.", LOG_LEVEL_0);
+ }
+ string_tools::trim(command);
- LOG_PRINT_L2("Read command: " << command);
- if (command.empty())
- {
- continue;
- }
- else if(cmd_handler(command))
- {
- continue;
- }
- else if(0 == command.compare("exit") || 0 == command.compare("q"))
- {
- continue_handle = false;
+ LOG_PRINT_L2("Read command: " << command);
+ if (command.empty())
+ {
+ continue;
+ }
+ else if(cmd_handler(command))
+ {
+ continue;
+ }
+ else if(0 == command.compare("exit") || 0 == command.compare("q"))
+ {
+ continue_handle = false;
+ }
+ else
+ {
+ std::cout << "unknown command: " << command << std::endl;
+ std::cout << usage;
+ }
}
- else
+ catch (const std::exception &ex)
{
- std::cout << "unknown command: " << command << std::endl;
- std::cout << usage;
+ LOG_ERROR("Exception at [console_handler], what=" << ex.what());
}
}
if (exit_handler)
exit_handler();
return true;
- CATCH_ENTRY_L0("console_handler", false);
}
private: