1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

Use real types instead of enums to distinguish exceptions

This commit is contained in:
Pavel Labath 2010-11-15 00:24:49 +01:00
parent c2c06d0956
commit 97ac409903
2 changed files with 21 additions and 14 deletions

View File

@ -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

View File

@ -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;