From 5a7ec7fb0b03cceb3c9fbd8337aeffcf0780a0f5 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sun, 21 Nov 2010 22:44:04 +0100 Subject: [PATCH] Simplify exception handling and get rid of conky::critical_error As i said in my rant somewhere, it's up to the person catching the exception to decide if the error is critical or not. The person throwing the exception should specify the type of error and that's where his job ends. --- src/conky.cc | 15 ++++++--------- src/logging.h | 7 ------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 7884adde..04a20e95 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2657,20 +2657,21 @@ void load_config_file() } #ifdef BUILD_OLD_CONFIG catch(lua::syntax_error &e) { + NORM_ERR("Syntax error (%s) while reading config file. " + "Assuming it's in old syntax and attempting conversion.", e.what()); // the strchr thingy skips the first line (#! /usr/bin/lua) l.loadstring(strchr(convertconf, '\n')); l.pushstring(current_config.c_str()); l.call(1, 1); } #endif - catch(lua::file_error &e) { throw conky::critical_error(_("no configfile given")); } l.call(0, 0); l.getglobal("conky"); l.getfield(-1, "text"); l.replace(-2); if(l.type(-1) != lua::TSTRING) - throw conky::critical_error(_("missing text block in configuration")); + throw conky::error(_("missing text block in configuration")); /* Remove \\-\n. */ l.gsub(l.tocstring(-1), "\\\n", ""); @@ -2815,7 +2816,7 @@ void set_current_config() { current_config = builtin_config_magic; NORM_ERR(NOCFGFILEFOUND ", using builtin default"); #else - throw conky::critical_error(NOCFGFILEFOUND); + throw conky::error(NOCFGFILEFOUND); #endif } @@ -3094,10 +3095,6 @@ int main(int argc, char **argv) main_loop(); } - catch(conky::critical_error &e) { - std::cerr << "caught critical exception: " << e.what() << std::endl; - return EXIT_FAILURE; - } catch(fork_throw &e) { return EXIT_SUCCESS; } catch(unknown_arg_throw &e) { return EXIT_FAILURE; } catch(obj_create_error &e) { @@ -3105,8 +3102,8 @@ int main(int argc, char **argv) clean_up(NULL, NULL); return EXIT_FAILURE; } - catch(std::bad_alloc &e) { - std::cerr << e.what() << std::endl; + catch(std::exception &e) { + std::cerr << PACKAGE_NAME": " << e.what() << std::endl; return EXIT_FAILURE; } diff --git a/src/logging.h b/src/logging.h index c4ad6841..4c2b448e 100644 --- a/src/logging.h +++ b/src/logging.h @@ -90,13 +90,6 @@ namespace conky { : std::runtime_error(msg) {} }; - - class critical_error: public error { - public: - critical_error(const std::string &msg) - : error(msg) - {} - }; } /* debugging output */