1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 04:32:55 +00:00

Replace a CRIT_ERR in combine by trying,throwing and catching

PS: I want to replace all similar CRIT_ERR's like this, opinions ?
This commit is contained in:
Nikolas Garofil 2010-11-16 13:41:44 +01:00
parent fd9dd921a4
commit 8123e447e2
5 changed files with 36 additions and 6 deletions

View File

@ -40,7 +40,7 @@ struct combine_data {
char *right; char *right;
}; };
void parse_combine_arg(struct text_object *obj, const char *arg, void *free_at_crash) void parse_combine_arg(struct text_object *obj, const char *arg)
{ {
struct combine_data *cd; struct combine_data *cd;
unsigned int i,j; unsigned int i,j;
@ -89,7 +89,7 @@ void parse_combine_arg(struct text_object *obj, const char *arg, void *free_at_c
extract_variable_text_internal(obj->sub->sub, cd->right); extract_variable_text_internal(obj->sub->sub, cd->right);
obj->data.opaque = cd; obj->data.opaque = cd;
} else { } else {
CRIT_ERR(obj, free_at_crash, "combine needs arguments: <text1> <text2>"); throw combine_needs_2_args_error();
} }
} }

View File

@ -30,7 +30,7 @@
#ifndef _COMBINE_H #ifndef _COMBINE_H
#define _COMBINE_H #define _COMBINE_H
void parse_combine_arg(struct text_object *, const char *, void *); void parse_combine_arg(struct text_object *, const char *);
void print_combine(struct text_object *, char *, int); void print_combine(struct text_object *, char *, int);
void free_combine(struct text_object *); void free_combine(struct text_object *);

View File

@ -4495,6 +4495,11 @@ int main(int argc, char **argv)
} }
catch(fork_throw &e) { return EXIT_SUCCESS; } catch(fork_throw &e) { return EXIT_SUCCESS; }
catch(unknown_arg_throw &e) { return EXIT_FAILURE; } catch(unknown_arg_throw &e) { return EXIT_FAILURE; }
catch(obj_create_error &e) {
std::cerr << e.what() << std::endl;
clean_up(NULL, NULL);
return EXIT_FAILURE;
}
#ifdef BUILD_CURL #ifdef BUILD_CURL
curl_global_cleanup(); curl_global_cleanup();

View File

@ -1726,8 +1726,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long
parse_scroll_arg(obj, arg, free_at_crash, s); parse_scroll_arg(obj, arg, free_at_crash, s);
obj->callbacks.print = &print_scroll; obj->callbacks.print = &print_scroll;
obj->callbacks.free = &free_scroll; obj->callbacks.free = &free_scroll;
END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>") END OBJ(combine, 0)
parse_combine_arg(obj, arg, free_at_crash); try {
parse_combine_arg(obj, arg);
}
catch(combine_needs_2_args_error &e) {
free(obj);
throw obj_create_error(e.what());
}
obj->callbacks.print = &print_combine; obj->callbacks.print = &print_combine;
obj->callbacks.free = &free_combine; obj->callbacks.free = &free_combine;
#ifdef BUILD_NVIDIA #ifdef BUILD_NVIDIA
@ -1955,8 +1961,15 @@ int extract_variable_text_internal(struct text_object *retval, const char *const
tmp_p++; tmp_p++;
} }
obj = construct_text_object(buf, arg, try {
obj = construct_text_object(buf, arg,
line, &ifblock_opaque, orig_p); line, &ifblock_opaque, orig_p);
}
catch(obj_create_error &e) {
free(buf);
free(orig_p);
throw e;
}
if (obj != NULL) { if (obj != NULL) {
append_object(retval, obj); append_object(retval, obj);
} }

View File

@ -47,6 +47,18 @@ public:
unknown_arg_throw(const std::string &msg) : std::runtime_error(msg) {} unknown_arg_throw(const std::string &msg) : std::runtime_error(msg) {}
}; };
class combine_needs_2_args_error : public std::runtime_error {
public:
combine_needs_2_args_error() : std::runtime_error("combine needs arguments: <text1> <text2>") {}
combine_needs_2_args_error(const std::string &msg) : std::runtime_error(msg) {}
};
class obj_create_error : public std::runtime_error {
public:
obj_create_error() : std::runtime_error("Failed to create object") {}
obj_create_error(const std::string &msg) : std::runtime_error(msg) {}
};
void clean_up(void *memtofree1, void* memtofree2); void clean_up(void *memtofree1, void* memtofree2);
void clean_up_without_threads(void *memtofree1, void* memtofree2); void clean_up_without_threads(void *memtofree1, void* memtofree2);