do not catch exception in commands, let them propagate

This commit is contained in:
Maxime Coste 2012-06-30 00:44:14 +02:00
parent f11d44246c
commit 603cfd3108

View File

@ -289,8 +289,7 @@ void quit(const CommandParameters& params, const Context& context)
message += *it; message += *it;
} }
message += "]"; message += "]";
print_status(message); throw runtime_error(message);
return;
} }
} }
quit_requested = true; quit_requested = true;
@ -354,26 +353,20 @@ void add_highlighter(const CommandParameters& params, const Context& context)
ParametersParser parser(params, { { "group", true } }); ParametersParser parser(params, { { "group", true } });
if (parser.positional_count() < 1) if (parser.positional_count() < 1)
throw wrong_argument_count(); throw wrong_argument_count();
try
{
HighlighterRegistry& registry = HighlighterRegistry::instance();
auto begin = parser.begin(); HighlighterRegistry& registry = HighlighterRegistry::instance();
const String& name = *begin;
std::vector<String> highlighter_params(++begin, parser.end());
Window& window = context.window(); auto begin = parser.begin();
HighlighterGroup& group = parser.has_option("group") ? const String& name = *begin;
window.highlighters().get_group(parser.option_value("group")) std::vector<String> highlighter_params(++begin, parser.end());
: window.highlighters();
registry.add_highlighter_to_group(window, group, name, Window& window = context.window();
highlighter_params); HighlighterGroup& group = parser.has_option("group") ?
} window.highlighters().get_group(parser.option_value("group"))
catch (runtime_error& err) : window.highlighters();
{
print_status("error: " + err.description()); registry.add_highlighter_to_group(window, group, name,
} highlighter_params);
} }
void rm_highlighter(const CommandParameters& params, const Context& context) void rm_highlighter(const CommandParameters& params, const Context& context)
@ -381,19 +374,13 @@ void rm_highlighter(const CommandParameters& params, const Context& context)
ParametersParser parser(params, { { "group", true } }); ParametersParser parser(params, { { "group", true } });
if (parser.positional_count() != 1) if (parser.positional_count() != 1)
throw wrong_argument_count(); throw wrong_argument_count();
try
{
Window& window = context.window();
HighlighterGroup& group = parser.has_option("group") ?
window.highlighters().get_group(parser.option_value("group"))
: window.highlighters();
group.remove(*parser.begin()); Window& window = context.window();
} HighlighterGroup& group = parser.has_option("group") ?
catch (runtime_error& err) window.highlighters().get_group(parser.option_value("group"))
{ : window.highlighters();
print_status("error: " + err.description());
} group.remove(*parser.begin());
} }
void add_filter(const CommandParameters& params, const Context& context) void add_filter(const CommandParameters& params, const Context& context)
@ -401,25 +388,19 @@ void add_filter(const CommandParameters& params, const Context& context)
ParametersParser parser(params, { { "group", true } }); ParametersParser parser(params, { { "group", true } });
if (parser.positional_count() < 1) if (parser.positional_count() < 1)
throw wrong_argument_count(); throw wrong_argument_count();
try
{
FilterRegistry& registry = FilterRegistry::instance();
auto begin = parser.begin(); FilterRegistry& registry = FilterRegistry::instance();
const String& name = *begin;
std::vector<String> filter_params(++begin, parser.end());
Window& window = context.window(); auto begin = parser.begin();
FilterGroup& group = parser.has_option("group") ? const String& name = *begin;
window.filters().get_group(parser.option_value("group")) std::vector<String> filter_params(++begin, parser.end());
: window.filters();
registry.add_filter_to_group(group, name, filter_params); Window& window = context.window();
} FilterGroup& group = parser.has_option("group") ?
catch (runtime_error& err) window.filters().get_group(parser.option_value("group"))
{ : window.filters();
print_status("error: " + err.description());
} registry.add_filter_to_group(group, name, filter_params);
} }
void rm_filter(const CommandParameters& params, const Context& context) void rm_filter(const CommandParameters& params, const Context& context)
@ -427,19 +408,13 @@ void rm_filter(const CommandParameters& params, const Context& context)
ParametersParser parser(params, { { "group", true } }); ParametersParser parser(params, { { "group", true } });
if (parser.positional_count() != 1) if (parser.positional_count() != 1)
throw wrong_argument_count(); throw wrong_argument_count();
try
{
Window& window = context.window();
FilterGroup& group = parser.has_option("group") ?
window.filters().get_group(parser.option_value("group"))
: window.filters();
group.remove(*parser.begin()); Window& window = context.window();
} FilterGroup& group = parser.has_option("group") ?
catch (runtime_error& err) window.filters().get_group(parser.option_value("group"))
{ : window.filters();
print_status("error: " + err.description());
} group.remove(*parser.begin());
} }
void add_hook(const CommandParameters& params, const Context& context) void add_hook(const CommandParameters& params, const Context& context)
@ -463,7 +438,7 @@ void add_hook(const CommandParameters& params, const Context& context)
else if (params[0] == "window") else if (params[0] == "window")
context.window().hook_manager().add_hook(params[1], hook_func); context.window().hook_manager().add_hook(params[1], hook_func);
else else
print_status("error: no such hook container " + params[0]); throw runtime_error("error: no such hook container " + params[0]);
} }
EnvVarMap params_to_env_var_map(const CommandParameters& params) EnvVarMap params_to_env_var_map(const CommandParameters& params)
@ -583,10 +558,7 @@ void exec_commands_in_file(const CommandParameters& params,
++end_pos; ++end_pos;
if (end_pos == length) if (end_pos == length)
{ throw(String("unterminated '") + delimiter + "' string");
print_status(String("unterminated '") + delimiter + "' string");
return;
}
++end_pos; ++end_pos;
} }
@ -609,8 +581,9 @@ void exec_commands_in_file(const CommandParameters& params,
if (end_pos == length) if (end_pos == length)
{ {
if (cat_with_previous) if (cat_with_previous)
print_status("while executing commands in \"" + params[0] + throw runtime_error("while executing commands in \"" +
"\": last command not complete"); params[0] +
"\": last command not complete");
break; break;
} }
pos = end_pos + 1; pos = end_pos + 1;