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,8 +353,7 @@ 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(); HighlighterRegistry& registry = HighlighterRegistry::instance();
auto begin = parser.begin(); auto begin = parser.begin();
@ -369,11 +367,6 @@ void add_highlighter(const CommandParameters& params, const Context& context)
registry.add_highlighter_to_group(window, group, name, registry.add_highlighter_to_group(window, group, name,
highlighter_params); highlighter_params);
}
catch (runtime_error& err)
{
print_status("error: " + err.description());
}
} }
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(); Window& window = context.window();
HighlighterGroup& group = parser.has_option("group") ? HighlighterGroup& group = parser.has_option("group") ?
window.highlighters().get_group(parser.option_value("group")) window.highlighters().get_group(parser.option_value("group"))
: window.highlighters(); : window.highlighters();
group.remove(*parser.begin()); group.remove(*parser.begin());
}
catch (runtime_error& err)
{
print_status("error: " + err.description());
}
} }
void add_filter(const CommandParameters& params, const Context& context) void add_filter(const CommandParameters& params, const Context& context)
@ -401,8 +388,7 @@ 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(); FilterRegistry& registry = FilterRegistry::instance();
auto begin = parser.begin(); auto begin = parser.begin();
@ -415,11 +401,6 @@ void add_filter(const CommandParameters& params, const Context& context)
: window.filters(); : window.filters();
registry.add_filter_to_group(group, name, filter_params); registry.add_filter_to_group(group, name, filter_params);
}
catch (runtime_error& err)
{
print_status("error: " + err.description());
}
} }
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(); Window& window = context.window();
FilterGroup& group = parser.has_option("group") ? FilterGroup& group = parser.has_option("group") ?
window.filters().get_group(parser.option_value("group")) window.filters().get_group(parser.option_value("group"))
: window.filters(); : window.filters();
group.remove(*parser.begin()); group.remove(*parser.begin());
}
catch (runtime_error& err)
{
print_status("error: " + err.description());
}
} }
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,7 +581,8 @@ 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 \"" +
params[0] +
"\": last command not complete"); "\": last command not complete");
break; break;
} }