From 97ac40990397f3367856aca37bdacaf9b8b8698f Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 15 Nov 2010 00:24:49 +0100 Subject: [PATCH] Use real types instead of enums to distinguish exceptions --- src/conky.cc | 9 ++++++--- src/logging.h | 26 +++++++++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index e42789de..0aa45955 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2646,7 +2646,7 @@ void load_config_file() l.getfield(-1, "text"); l.replace(-2); if(l.type(-1) != lua::TSTRING) - throw conky_error(critical, "missing text block in configuration; exiting"); + throw conky::critical_error(_("missing text block in configuration")); /* Remove \\-\n. */ l.gsub(l.tocstring(-1), "\\\n", ""); @@ -3053,9 +3053,12 @@ int main(int argc, char **argv) first_pass = 0; /* don't ever call fork() again */ } - catch(conky_error &e) { + catch(conky::critical_error &e) { + std::cerr << "caught critical exception: " << e.what() << std::endl; + return EXIT_FAILURE; + } + catch(std::runtime_error &e) { std::cerr << "caught exception: " << e.what() << std::endl; - if(e.errortype() == critical) return EXIT_FAILURE; } #ifdef BUILD_WEATHER_XOAP diff --git a/src/logging.h b/src/logging.h index 661ddf62..8f1147e8 100644 --- a/src/logging.h +++ b/src/logging.h @@ -59,17 +59,21 @@ inline void gettextize_format(const char *format) #define THREAD_CRIT_ERR(memtofree1, memtofree2, ...) \ { NORM_ERR(__VA_ARGS__); clean_up_without_threads(memtofree1, memtofree2); return; } -enum error_type { normal, critical }; -class conky_error : public std::runtime_error { - error_type type; -public: - conky_error(error_type newtype, const std::string& error_mesg) : std::runtime_error(error_mesg) { - type = newtype; - } - error_type errortype() { - return type; - } -}; +namespace conky { + class error : public std::runtime_error { + public: + error(const std::string &msg) + : std::runtime_error(msg) + {} + }; + + class critical_error: public error { + public: + critical_error(const std::string &msg) + : error(msg) + {} + }; +} /* debugging output */ extern int global_debug_level;