diff --git a/src/command_manager.cc b/src/command_manager.cc index 9cf0c805..94182f4d 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -425,10 +425,15 @@ void CommandManager::execute_single_command(CommandParameters params, command_it->value.param_desc); command_it->value.func(parameter_parser, context, shell_context); } + catch (failure& error) + { + throw; + } catch (runtime_error& error) { - throw runtime_error(format("{}:{}: '{}' {}", pos.line+1, pos.column+1, - params[0], error.what())); + error.set_what(format("{}:{}: '{}' {}", pos.line+1, pos.column+1, + params[0], error.what())); + throw; } } diff --git a/src/commands.cc b/src/commands.cc index febc8f33..213926f7 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -2140,7 +2140,7 @@ const CommandDesc fail_cmd = { CommandCompleter{}, [](const ParametersParser& parser, Context&, const ShellContext&) { - throw runtime_error(fix_atom_text(join(parser, ' ', false))); + throw failure{fix_atom_text(join(parser, " "))}; } }; diff --git a/src/exception.hh b/src/exception.hh index 4967e15b..0ff3d825 100644 --- a/src/exception.hh +++ b/src/exception.hh @@ -18,11 +18,17 @@ struct runtime_error : exception : m_what(std::move(what)) {} StringView what() const override { return m_what; } + void set_what(String what) { m_what = std::move(what); } private: String m_what; }; +struct failure : runtime_error +{ + using runtime_error::runtime_error; +}; + struct logic_error : exception { };