From 0bf09c82a51b7a1e0ba414ffb59dbcebda1c3340 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sun, 13 May 2018 15:47:29 +1100 Subject: [PATCH] Catch all exceptions (where possible) as const references A few catch blocks modify something in their exceptions, so those are kept non-const. --- src/actions/attack.cpp | 6 +- src/actions/undo.cpp | 8 +-- src/addon/client.cpp | 2 +- src/addon/manager_ui.cpp | 4 +- src/ai/actions.cpp | 2 +- src/ai/composite/component.cpp | 2 +- src/ai/composite/goal.cpp | 2 +- src/ai/configuration.cpp | 2 +- src/ai/formula/ai.cpp | 8 +-- src/ai/formula/candidates.cpp | 10 ++-- src/ai/formula/stage_unit_formulas.cpp | 2 +- src/campaign_server/campaign_server.cpp | 10 ++-- src/commandline_options.cpp | 6 +- src/config_cache.cpp | 12 ++-- src/display.cpp | 2 +- src/editor/controller/editor_controller.cpp | 6 +- src/editor/editor_main.cpp | 2 +- src/editor/map/context_manager.cpp | 16 ++--- src/editor/map/editor_map.cpp | 6 +- src/editor/map/map_context.cpp | 8 +-- src/filesystem_boost.cpp | 2 +- src/font/font_config.cpp | 2 +- src/formula/formula.cpp | 12 ++-- src/formula/variant_value.hpp | 2 +- src/game_config.cpp | 10 ++-- src/game_config_manager.cpp | 12 ++-- src/game_events/action_wml.cpp | 8 +-- src/game_initialization/create_engine.cpp | 14 ++--- src/game_initialization/lobby_data.cpp | 4 +- src/game_initialization/lobby_info.cpp | 4 +- src/game_initialization/multiplayer.cpp | 6 +- src/game_initialization/playcampaign.cpp | 14 ++--- src/game_initialization/singleplayer.cpp | 2 +- src/game_launcher.cpp | 60 +++++++++---------- src/generators/cave_map_generator.cpp | 4 +- src/generators/default_map_generator.cpp | 4 +- src/generators/lua_map_generator.cpp | 6 +- src/gettext_boost.cpp | 4 +- src/gui/dialogs/advanced_graphics_options.cpp | 2 +- src/gui/dialogs/editor/custom_tod.cpp | 2 +- src/gui/dialogs/game_load.cpp | 2 +- src/gui/dialogs/lua_interpreter.cpp | 2 +- src/gui/dialogs/multiplayer/lobby.cpp | 2 +- src/gui/dialogs/preferences_dialog.cpp | 2 +- src/gui/dialogs/story_viewer.hpp | 2 +- src/gui/dialogs/title_screen.cpp | 2 +- src/gui/dialogs/tooltip.cpp | 4 +- src/gui/gui.cpp | 2 +- src/gui/widgets/minimap.cpp | 2 +- src/gui/widgets/size_lock.cpp | 2 +- src/gui/widgets/window.cpp | 6 +- src/halo.cpp | 2 +- src/image.cpp | 4 +- src/image_modifications.cpp | 10 ++-- src/language.cpp | 2 +- src/language.hpp | 2 +- src/lexical_cast.hpp | 20 +++---- src/map/label.cpp | 2 +- src/map/location.cpp | 12 ++-- src/map/map.cpp | 2 +- src/menu_events.cpp | 8 +-- src/mouse_events.cpp | 2 +- src/persist_context.cpp | 2 +- src/playmp_controller.cpp | 4 +- src/playsingle_controller.cpp | 10 ++-- src/preferences/credentials.cpp | 2 +- src/preferences/general.cpp | 2 +- src/replay.cpp | 2 +- src/save_blocker.cpp | 2 +- src/save_index.cpp | 10 ++-- src/savegame.cpp | 8 +-- src/scripting/game_lua_kernel.cpp | 2 +- src/scripting/lua_kernel_base.cpp | 4 +- src/serialization/preprocessor.cpp | 4 +- src/serialization/schema_validator.cpp | 4 +- src/serialization/string_utils.cpp | 4 +- src/serialization/unicode.cpp | 4 +- src/serialization/unicode_cast.hpp | 4 +- src/server/ban.cpp | 18 +++--- src/server/forum_user_handler.cpp | 32 +++++----- src/server/game.cpp | 4 +- src/server/server.cpp | 20 +++---- src/server/simple_wml.cpp | 6 +- src/side_filter.cpp | 2 +- src/statistics.cpp | 2 +- src/synced_commands.cpp | 4 +- src/terrain/builder.cpp | 6 +- src/terrain/filter.cpp | 2 +- src/terrain/translation.cpp | 2 +- src/tests/gui/test_gui2.cpp | 32 +++++----- src/tests/test_make_enum.cpp | 8 +-- src/tod_manager.cpp | 2 +- src/units/abilities.cpp | 2 +- src/units/attack_type.cpp | 2 +- src/units/filter.cpp | 2 +- src/units/frame_private.hpp | 8 +-- src/units/unit.cpp | 2 +- src/variable.cpp | 2 +- src/wesnoth.cpp | 32 +++++----- src/whiteboard/move.cpp | 2 +- src/whiteboard/side_actions.cpp | 2 +- 101 files changed, 323 insertions(+), 323 deletions(-) diff --git a/src/actions/attack.cpp b/src/actions/attack.cpp index 67f1bbd60b74..e4a8cbabf7c8 100644 --- a/src/actions/attack.cpp +++ b/src/actions/attack.cpp @@ -1202,14 +1202,14 @@ bool attack::perform_hit(bool attacker_turn, statistics::attack_context& stats) if(hits) { try { fire_event(attacker_turn ? "attacker_hits" : "defender_hits"); - } catch(attack_end_exception) { + } catch(const attack_end_exception&) { refresh_bc(); return false; } } else { try { fire_event(attacker_turn ? "attacker_misses" : "defender_misses"); - } catch(attack_end_exception) { + } catch(const attack_end_exception&) { refresh_bc(); return false; } @@ -1434,7 +1434,7 @@ void attack::perform() try { fire_event("attack"); - } catch(attack_end_exception) { + } catch(const attack_end_exception&) { return; } diff --git a/src/actions/undo.cpp b/src/actions/undo.cpp index 91f9fb92c730..e6f547d93166 100644 --- a/src/actions/undo.cpp +++ b/src/actions/undo.cpp @@ -298,11 +298,11 @@ void undo_list::read(const config & cfg) if ( action ) { undos_.push_back(action); } - } catch (bad_lexical_cast &) { + } catch (const bad_lexical_cast &) { ERR_NG << "Error when parsing undo list from config: bad lexical cast." << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this undo action..." << std::endl; - } catch (config::error& e) { + } catch (const config::error& e) { ERR_NG << "Error when parsing undo list from config: " << e.what() << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this undo action..." << std::endl; @@ -313,11 +313,11 @@ void undo_list::read(const config & cfg) for (const config & child : cfg.child_range("redo")) { try { redos_.push_back(new config(child)); - } catch (bad_lexical_cast &) { + } catch (const bad_lexical_cast &) { ERR_NG << "Error when parsing redo list from config: bad lexical cast." << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this redo action..." << std::endl; - } catch (config::error& e) { + } catch (const config::error& e) { ERR_NG << "Error when parsing redo list from config: " << e.what() << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this redo action..." << std::endl; diff --git a/src/addon/client.cpp b/src/addon/client.cpp index fdafc8d2e431..29c96326ded8 100644 --- a/src/addon/client.cpp +++ b/src/addon/client.cpp @@ -148,7 +148,7 @@ bool addons_client::upload_addon(const std::string& id, std::string& response_me config addon_data; try { archive_addon(id, addon_data); - } catch(utf8::invalid_utf8_exception&){ + } catch(const utf8::invalid_utf8_exception&){ this->last_error_ = VGETTEXT("The add-on $addon_title has a file or directory " "containing invalid characters and cannot be published.", i18n_symbols); diff --git a/src/addon/manager_ui.cpp b/src/addon/manager_ui.cpp index 22282db3756e..06ca32a40125 100644 --- a/src/addon/manager_ui.cpp +++ b/src/addon/manager_ui.cpp @@ -95,7 +95,7 @@ bool addons_manager_ui(const std::string& remote_address) gui2::show_error_message( VGETTEXT("A local file with add-on publishing information could not be read.\n\nFile: $path\nError message: $msg", symbols)); - } catch(wml_exception& e) { + } catch(const wml_exception& e) { e.show(); } catch(const addons_client::user_exit&) { LOG_AC << "initial connection canceled by user\n"; @@ -306,7 +306,7 @@ bool ad_hoc_addon_fetch_session(const std::vector& addon_ids) gui2::show_error_message( VGETTEXT("A local file with add-on publishing information could not be read.\n\nFile: $path\nError message: $msg", symbols)); - } catch(wml_exception& e) { + } catch(const wml_exception& e) { e.show(); } catch(const addons_client::user_exit&) { LOG_AC << "initial connection canceled by user\n"; diff --git a/src/ai/actions.cpp b/src/ai/actions.cpp index 5112a21b122f..fff470b7104d 100644 --- a/src/ai/actions.cpp +++ b/src/ai/actions.cpp @@ -96,7 +96,7 @@ void action_result::execute() if (is_success()){ try { do_execute(); - } catch (return_to_play_side_exception&) { + } catch (const return_to_play_side_exception&) { if (!is_ok()) { DBG_AI_ACTIONS << "Return value of AI ACTION was not checked." << std::endl; } //Demotes to DBG "unchecked result" warning throw; } diff --git a/src/ai/composite/component.cpp b/src/ai/composite/component.cpp index c1de2881b85f..d5dd8fe06e5a 100644 --- a/src/ai/composite/component.cpp +++ b/src/ai/composite/component.cpp @@ -160,7 +160,7 @@ static component *find_component(component *root, const std::string &path, path_ } else { try { pe.position = std::stoi(position); - } catch (std::invalid_argument&) { + } catch (const std::invalid_argument&) { pe.position = -2; } } diff --git a/src/ai/composite/goal.cpp b/src/ai/composite/goal.cpp index 156ee22478f8..5aaaf552dcb2 100644 --- a/src/ai/composite/goal.cpp +++ b/src/ai/composite/goal.cpp @@ -334,7 +334,7 @@ void lua_goal::add_targets(std::back_insert_iterator< std::vector< target >> tar { *target_list = tg; } - } catch(bad_enum_cast& e) { + } catch(const bad_enum_cast& e) { ERR_AI_GOAL << "A Lua goal returned a target of an unknown type (\"" << e.value() << "\"; unfortunately, the engine cannot recover from this error. As a result, all targets returned by the goal have been lost.\n"; } diff --git a/src/ai/configuration.cpp b/src/ai/configuration.cpp index c3794da770ff..032be24bd314 100644 --- a/src/ai/configuration.cpp +++ b/src/ai/configuration.cpp @@ -172,7 +172,7 @@ bool configuration::get_side_config_from_file(const std::string& file, config& c filesystem::scoped_istream stream = preprocess_file(filesystem::get_wml_location(file)); read(cfg, *stream); LOG_AI_CONFIGURATION << "Reading AI configuration from file '" << file << "'" << std::endl; - } catch(config::error &) { + } catch(const config::error &) { ERR_AI_CONFIGURATION << "Error while reading AI configuration from file '" << file << "'" << std::endl; return false; } diff --git a/src/ai/formula/ai.cpp b/src/ai/formula/ai.cpp index c00cc072cd67..273906b36f1e 100644 --- a/src/ai/formula/ai.cpp +++ b/src/ai/formula/ai.cpp @@ -86,7 +86,7 @@ ca_ptr formula_ai::load_candidate_action_from_config(const config& rc_action) } else { ERR_AI << "Unknown candidate action type: " << type << std::endl; } - } catch(formula_error& e) { + } catch(const formula_error& e) { handle_exception(e, "Error while registering candidate action '" + name + "'"); } return new_ca; @@ -144,7 +144,7 @@ formula_ptr formula_ai::create_optional_formula(const std::string& formula_strin try{ return formula::create_optional_formula(formula_string, &function_table_); } - catch(formula_error& e) { + catch(const formula_error& e) { handle_exception(e); return wfl::formula_ptr(); } @@ -656,7 +656,7 @@ void formula_ai::on_create(){ create_optional_formula(func["precondition"]), args); } - catch(formula_error& e) { + catch(const formula_error& e) { handle_exception(e, "Error while registering function '" + name + "'"); } } @@ -752,7 +752,7 @@ config formula_ai::to_config() const { try { str = i->second.serialize_to_string(); - } catch (type_error&) { + } catch(const type_error&) { WRN_AI << "variable ["<< i->first <<"] is not serializable - it will not be persisted across savegames"<handle_exception(e); res = 0; - } catch(type_error& e) { + } catch(const type_error& e) { res = 0; ERR_AI << "formula type error while evaluating candidate action: " << e.message << std::endl; } @@ -116,7 +116,7 @@ void move_candidate_action::evaluate(ai::formula_ai* ai, unit_map& units) else filtered_units=my_units; } - catch(formula_error& e) { + catch(const formula_error& e) { ai->handle_exception(e, "Error while executing filter formula for '" + get_name() + "' Candidate Action"); return; } @@ -186,7 +186,7 @@ void attack_candidate_action::evaluate(ai::formula_ai* ai, unit_map& units) else filtered_enemy_units = enemy_units; } - catch(formula_error& e) { + catch(const formula_error& e) { ai->handle_exception(e, "Error while executing filter formula for '" + get_name() + "' Candidate Action"); return; } @@ -195,7 +195,7 @@ void attack_candidate_action::evaluate(ai::formula_ai* ai, unit_map& units) if( !(filtered_enemy_units.num_elements() && filtered_my_units.num_elements() ) ) return; } - catch(type_error& e) { + catch(const type_error& e) { ERR_AI << "Error while executing filter formulas for '" + get_name() + "' Candidate Action: " << e.message << std::endl; return; } diff --git a/src/ai/formula/stage_unit_formulas.cpp b/src/ai/formula/stage_unit_formulas.cpp index 7141106de03f..dc8cf6182e7f 100644 --- a/src/ai/formula/stage_unit_formulas.cpp +++ b/src/ai/formula/stage_unit_formulas.cpp @@ -78,7 +78,7 @@ bool stage_unit_formulas::do_play_stage() fai_.handle_exception( e, "Unit priority formula error for unit: '" + i->type_id() + "' standing at (" + std::to_string(i->get_location().wml_x()) + "," + std::to_string(i->get_location().wml_y()) + ")"); priority = 0; - } catch(wfl::type_error& e) { + } catch(const wfl::type_error& e) { priority = 0; ERR_AI << "formula type error while evaluating unit priority formula " << e.message << std::endl; } diff --git a/src/campaign_server/campaign_server.cpp b/src/campaign_server/campaign_server.cpp index 4795cae4f0d9..0b27f73933cc 100644 --- a/src/campaign_server/campaign_server.cpp +++ b/src/campaign_server/campaign_server.cpp @@ -589,14 +589,14 @@ void server::handle_request_campaign_list(const server::request& req) try { before = before + lexical_cast(req.cfg["before"]); before_flag = true; - } catch(bad_lexical_cast) {} + } catch(const bad_lexical_cast&) {} bool after_flag = false; time_t after = epoch; try { after = after + lexical_cast(req.cfg["after"]); after_flag = true; - } catch(bad_lexical_cast) {} + } catch(const bad_lexical_cast&) {} const std::string& name = req.cfg["name"]; const std::string& lang = req.cfg["language"]; @@ -1009,13 +1009,13 @@ int main() const std::string cfg_path = filesystem::normalize_path("server.cfg"); campaignd::server(cfg_path).run(); - } catch(config::error& /*e*/) { + } catch(const config::error& /*e*/) { std::cerr << "Could not parse config file\n"; return 1; - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { std::cerr << "File I/O error: " << e.what() << "\n"; return 2; - } catch(std::bad_function_call& /*e*/) { + } catch(const std::bad_function_call& /*e*/) { std::cerr << "Bad request handler function call\n"; return 4; } diff --git a/src/commandline_options.cpp b/src/commandline_options.cpp index 6150f59cc3e5..25adb9ac36ea 100644 --- a/src/commandline_options.cpp +++ b/src/commandline_options.cpp @@ -518,7 +518,7 @@ void commandline_options::parse_resolution_ ( const std::string& resolution_stri try { xres = std::stoi(tokens[0]); yres = std::stoi(tokens[1]); - } catch(std::invalid_argument &) { + } catch(const std::invalid_argument &) { throw bad_commandline_resolution(resolution_string); } @@ -541,7 +541,7 @@ std::vector> commandline_options::parse_to_u unsigned int temp; try { temp = lexical_cast(tokens[0]); - } catch (bad_lexical_cast &) { + } catch (const bad_lexical_cast &) { throw bad_commandline_tuple(s, expected_format); } @@ -566,7 +566,7 @@ std::vector> commandline_option unsigned int temp; try { temp = lexical_cast(tokens[0]); - } catch (bad_lexical_cast &) { + } catch (const bad_lexical_cast &) { throw bad_commandline_tuple(s, expected_format); } diff --git a/src/config_cache.cpp b/src/config_cache.cpp index ae576d5c8336..5e38fa274852 100644 --- a/src/config_cache.cpp +++ b/src/config_cache.cpp @@ -175,9 +175,9 @@ void config_cache::read_cache(const std::string& file_path, config& cfg) dir_checksum = filesystem::file_tree_checksum(checksum_cfg); } - } catch(config::error&) { + } catch(const config::error&) { ERR_CACHE << "cache checksum is corrupt" << std::endl; - } catch(filesystem::io_exception&) { + } catch(const filesystem::io_exception&) { ERR_CACHE << "error reading cache checksum" << std::endl; } } @@ -199,11 +199,11 @@ void config_cache::read_cache(const std::string& file_path, config& cfg) } return; - } catch(config::error& e) { + } catch(const config::error& e) { ERR_CACHE << "cache " << fname << extension << " is corrupt. Loading from files: "<< e.message << std::endl; - } catch(filesystem::io_exception&) { + } catch(const filesystem::io_exception&) { ERR_CACHE << "error reading cache " << fname << extension << ". Loading from files" << std::endl; - } catch (boost::iostreams::gzip_error& e) { + } catch (const boost::iostreams::gzip_error& e) { //read_file -> ... -> read_gz can throw this exception. ERR_CACHE << "cache " << fname << extension << " is corrupt. Error code: " << e.error() << std::endl; } @@ -227,7 +227,7 @@ void config_cache::read_cache(const std::string& file_path, config& cfg) filesystem::data_tree_checksum().write(checksum_cfg); write_file(fname_checksum, checksum_cfg); - } catch(filesystem::io_exception&) { + } catch(const filesystem::io_exception&) { ERR_CACHE << "could not write to cache '" << fname << "'" << std::endl; } diff --git a/src/display.cpp b/src/display.cpp index 314a1bdc13eb..4507080ed44c 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -341,7 +341,7 @@ void display::init_flags_for_side_internal(size_t n, const std::string& side_col str = sub_items.front(); try { time = std::max(1, std::stoi(sub_items.back())); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_DP << "Invalid time value found when constructing flag for side " << n << ": " << sub_items.back() << "\n"; } } diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index 0b7151d385c4..04a6e21b6869 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -174,10 +174,10 @@ EXIT_STATUS editor_controller::main_loop() while (!do_quit_) { play_slice(); } - } catch (editor_exception& e) { + } catch (const editor_exception& e) { gui2::show_transient_message(_("Fatal error"), e.what()); return EXIT_ERROR; - } catch (wml_exception& e) { + } catch (const wml_exception& e) { e.show(); } return quit_mode_; @@ -193,7 +193,7 @@ void editor_controller::do_screenshot(const std::string& screenshot_filename /* if(screenshot.null() || image::save_image(screenshot, screenshot_filename) != image::save_result::success) { ERR_ED << "Screenshot creation failed!\n"; } - } catch (wml_exception& e) { + } catch (const wml_exception& e) { e.show(); } } diff --git a/src/editor/editor_main.cpp b/src/editor/editor_main.cpp index 8e5e220e16d6..c63aa4cf7731 100644 --- a/src/editor/editor_main.cpp +++ b/src/editor/editor_main.cpp @@ -62,7 +62,7 @@ EXIT_STATUS start(const config& game_conf, const std::string& filename /* = "" * if (!take_screenshot) e = editor.main_loop(); - } catch (editor_exception& e) { + } catch(const editor_exception& e) { ERR_ED << "Editor exception in editor::start: " << e.what() << std::endl; throw; } diff --git a/src/editor/map/context_manager.cpp b/src/editor/map/context_manager.cpp index 208547abbfe6..7f541e14d826 100644 --- a/src/editor/map/context_manager.cpp +++ b/src/editor/map/context_manager.cpp @@ -472,10 +472,10 @@ void context_manager::apply_mask_dialog() map_context mask(game_config_, dlg.path()); editor_action_apply_mask a(mask.map()); perform_refresh(a); - } catch (editor_map_load_exception& e) { + } catch (const editor_map_load_exception& e) { gui2::show_transient_message(_("Error loading mask"), e.what()); return; - } catch (editor_action_exception& e) { + } catch (const editor_action_exception& e) { gui2::show_error_message(e.what()); return; } @@ -515,10 +515,10 @@ void context_manager::create_mask_to_dialog() map_context map(game_config_, dlg.path()); editor_action_create_mask a(map.map()); perform_refresh(a); - } catch (editor_map_load_exception& e) { + } catch (const editor_map_load_exception& e) { gui2::show_transient_message(_("Error loading map"), e.what()); return; - } catch (editor_action_exception& e) { + } catch (const editor_action_exception& e) { gui2::show_error_message(e.what()); return; } @@ -708,7 +708,7 @@ void context_manager::generate_map_dialog() map_generator* const map_generator = dialog.get_selected_map_generator(); try { map_string = map_generator->create_map(dialog.get_seed()); - } catch (mapgen_exception& e) { + } catch (const mapgen_exception& e) { gui2::show_transient_message(_("Map creation failed."), e.what()); return; } @@ -835,7 +835,7 @@ bool context_manager::write_scenario(bool display_confirmation) if(display_confirmation) { gui2::show_transient_message("", _("Scenario saved.")); } - } catch (editor_map_save_exception& e) { + } catch (const editor_map_save_exception& e) { gui2::show_transient_message("", e.what()); return false; } @@ -850,7 +850,7 @@ bool context_manager::write_map(bool display_confirmation) if(display_confirmation) { gui2::show_transient_message("", _("Map saved.")); } - } catch (editor_map_save_exception& e) { + } catch (const editor_map_save_exception& e) { gui2::show_transient_message("", e.what()); return false; } @@ -925,7 +925,7 @@ void context_manager::load_map(const std::string& filename, bool new_context) } } } - } catch (editor_map_load_exception& e) { + } catch(const editor_map_load_exception& e) { gui2::show_transient_message(_("Error loading map"), e.what()); return; } diff --git a/src/editor/map/editor_map.cpp b/src/editor/map/editor_map.cpp index 2f878a17777c..87e52e232d9b 100644 --- a/src/editor/map/editor_map.cpp +++ b/src/editor/map/editor_map.cpp @@ -56,11 +56,11 @@ editor_map editor_map::from_string(const config& terrain_cfg, const std::string& { try { return editor_map(terrain_cfg, data); - } catch (incorrect_map_format_error& e) { + } catch (const incorrect_map_format_error& e) { throw wrap_exc("format", e.message, ""); - } catch (wml_exception& e) { + } catch (const wml_exception& e) { throw wrap_exc("wml", e.user_message, ""); - } catch (config::error& e) { + } catch (const config::error& e) { throw wrap_exc("config", e.message, ""); } } diff --git a/src/editor/map/map_context.cpp b/src/editor/map/map_context.cpp index 1408f671e802..673d127e3c38 100644 --- a/src/editor/map/map_context.cpp +++ b/src/editor/map/map_context.cpp @@ -182,7 +182,7 @@ map_context::map_context(const config& game_config, const std::string& filename) // 4.0 editor generated scenario try { load_scenario(game_config); - } catch(config::error& e) { + } catch(const config::error& e) { // We already caught and rethrew this exception in load_scenario throw editor_map_load_exception("load_scenario", e.message); } @@ -318,7 +318,7 @@ void map_context::load_scenario(const config& game_config) try { read(scenario, *(preprocess_file(filename_))); - } catch(config::error& e) { + } catch(const config::error& e) { LOG_ED << "Caught a config error while parsing file: '" << filename_ << "'\n" << e.message << std::endl; throw; } @@ -598,7 +598,7 @@ bool map_context::save_scenario() } clear_modified(); - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { utils::string_map symbols; symbols["msg"] = e.what(); const std::string msg = VGETTEXT("Could not save the scenario: $msg", symbols); @@ -640,7 +640,7 @@ bool map_context::save_map() add_to_recent_files(); clear_modified(); - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { utils::string_map symbols; symbols["msg"] = e.what(); const std::string msg = VGETTEXT("Could not save the map: $msg", symbols); diff --git a/src/filesystem_boost.cpp b/src/filesystem_boost.cpp index dedf12b9682d..fdfeb2c4cfaa 100644 --- a/src/filesystem_boost.cpp +++ b/src/filesystem_boost.cpp @@ -910,7 +910,7 @@ filesystem::scoped_ostream ostream_file(const std::string& fname, bool create_di boost::iostreams::file_descriptor_sink fd(bfs::path(fname), std::ios_base::binary); return filesystem::scoped_ostream( new boost::iostreams::stream(fd, 4096, 0)); - } catch(BOOST_IOSTREAMS_FAILURE& e) { + } catch(const BOOST_IOSTREAMS_FAILURE& e) { // If this operation failed because the parent directory didn't exist, create the parent directory and // retry. error_code ec_unused; diff --git a/src/font/font_config.cpp b/src/font/font_config.cpp index 2ce95f39a89a..e6ca55193be0 100644 --- a/src/font/font_config.cpp +++ b/src/font/font_config.cpp @@ -139,7 +139,7 @@ bool load_font_config() filesystem::scoped_istream stream = preprocess_file(cfg_path); read(cfg, *stream); - } catch(config::error &e) { + } catch(const config::error &e) { ERR_FT << "could not read fonts.cfg:\n" << e.message << '\n'; return false; diff --git a/src/formula/formula.cpp b/src/formula/formula.cpp index 64c06cf50c32..a2d5f5e24002 100644 --- a/src/formula/formula.cpp +++ b/src/formula/formula.cpp @@ -39,7 +39,7 @@ namespace utils { try { const wfl::formula form(formula); return form.evaluate().string_cast(); - } catch(wfl::formula_error& e) { + } catch(const wfl::formula_error& e) { ERR_NG << "Formula in WML string cannot be evaluated due to " << e.type << "\n\t--> \""; return ""; @@ -205,7 +205,7 @@ formula::formula(const std::string& text, function_symbol_table* symbols) tokens.back().filename = &(*filenames_it); tokens.back().line_number = files.back().second; } - } catch(tk::token_error& e) { + } catch(const tk::token_error& e) { // When we catch token error, we should write whole line in which error occurred, // so we merge info from token and everything we had in the line so far std::string str = ""; @@ -263,7 +263,7 @@ variant formula::execute(const formula_callable& variables, formula_debugger*fdb { try { return expr_->evaluate(variables, fdb); - } catch(type_error& e) { + } catch(const type_error& e) { std::cerr << "formula type error: " << e.message << "\n"; return variant(); } @@ -1376,7 +1376,7 @@ expression_ptr parse_expression(const tk::token* i1, const tk::token* i2, functi parse_expression(tok + 1, i2 - 1, symbols) ) ); - } catch (formula_error& e){ + } catch (const formula_error& e){ throw formula_error( e.type, tokens_to_string(i1, i2-1), *i1->filename, i1->line_number ); } } @@ -1440,7 +1440,7 @@ expression_ptr parse_expression(const tk::token* i1, const tk::token* i2, functi try{ return symbols->create_function(std::string(i1->begin, i1->end),args); } - catch(formula_error& e) { + catch(const formula_error& e) { throw formula_error(e.type, tokens_to_string(function_call_begin, function_call_end), *i1->filename, i1->line_number); } } @@ -1457,7 +1457,7 @@ expression_ptr parse_expression(const tk::token* i1, const tk::token* i2, functi try{ return expression_ptr( new unary_operator_expression(std::string(op->begin, op->end), parse_expression(op + 1, i2 ,symbols))); - } catch(formula_error& e) { + } catch(const formula_error& e) { throw formula_error( e.type, tokens_to_string(begin,end - 1), *op->filename, op->line_number); } } diff --git a/src/formula/variant_value.hpp b/src/formula/variant_value.hpp index d445bc289a49..8d0427097be4 100644 --- a/src/formula/variant_value.hpp +++ b/src/formula/variant_value.hpp @@ -72,7 +72,7 @@ static T& value_ref_cast(variant_value_base& ptr) { try { return dynamic_cast(ptr); - } catch(std::bad_cast&) { + } catch(const std::bad_cast&) { throw type_error("Could not cast type"); } } diff --git a/src/game_config.cpp b/src/game_config.cpp index 35e63a825d35..fda3795ebaf9 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -394,7 +394,7 @@ void load_config(const config &v) for(const auto& s : utils::split(v[key].str())) { try { color_vec.push_back(color_t::from_hex_string(s)); - } catch(std::invalid_argument& e) { + } catch(const std::invalid_argument& e) { ERR_NG << "Error parsing color list '" << key << "'.\n" << e.what() << std::endl; color_vec.push_back(fallback); } @@ -467,7 +467,7 @@ void add_color_info(const config& v, bool build_defaults) for(const auto& s : utils::split(*a2)) { try { temp.push_back(color_t::from_hex_string(s)); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { std::stringstream ss; ss << "can't parse color string:\n" << teamC.debug() << "\n"; throw config::error(ss.str()); @@ -496,7 +496,7 @@ void add_color_info(const config& v, bool build_defaults) for(const auto& s : utils::split(rgb.second)) { try { temp.push_back(color_t::from_hex_string(s)); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_NG << "Invalid color in palette: " << s << std::endl; } } @@ -526,7 +526,7 @@ const color_range& color_info(const std::string& name) for(const auto& s : utils::split(name)) { try { temp.push_back(color_t::from_hex_string(s)); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { throw config::error(_("Invalid color in range: ") + s); } } @@ -546,7 +546,7 @@ const std::vector& tc_info(const std::string& name) for(const auto& s : utils::split(name)) { try { temp.push_back(color_t::from_hex_string(s)); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { static std::vector stv; ERR_NG << "Invalid color in palette: " << s << std::endl; return stv; diff --git a/src/game_config_manager.cpp b/src/game_config_manager.cpp index 785162f6f0bc..aea5b4043993 100644 --- a/src/game_config_manager.cpp +++ b/src/game_config_manager.cpp @@ -301,7 +301,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, tdata_ = std::make_shared(game_config_); ::init_strings(game_config()); theme::set_known_themes(&game_config()); - } catch(game::error& e) { + } catch(const game::error& e) { ERR_CONFIG << "Error loading game configuration files\n" << e.message << '\n'; // Try reloading without add-ons @@ -453,17 +453,17 @@ void game_config_manager::load_addons_cfg() } game_config_.append(umc_cfg); - } catch(config::error& err) { + } catch(const config::error& err) { ERR_CONFIG << "error reading usermade add-on '" << addon.main_cfg << "'" << std::endl; ERR_CONFIG << err.message << '\n'; error_addons.push_back(addon.main_cfg); error_log.push_back(err.message); - } catch(preproc_config::error& err) { + } catch(const preproc_config::error& err) { ERR_CONFIG << "error reading usermade add-on '" << addon.main_cfg << "'" << std::endl; ERR_CONFIG << err.message << '\n'; error_addons.push_back(addon.main_cfg); error_log.push_back(err.message); - } catch(filesystem::io_exception&) { + } catch(const filesystem::io_exception&) { ERR_CONFIG << "error reading usermade add-on '" << addon.main_cfg << "'" << std::endl; error_addons.push_back(addon.main_cfg); } @@ -557,7 +557,7 @@ void game_config_manager::load_game_config_for_game( try { load_game_config_with_loadscreen(NO_FORCE_RELOAD, &classification); - } catch(game::error&) { + } catch(const game::error&) { cache_.clear_defines(); std::deque previous_defines; @@ -584,7 +584,7 @@ void game_config_manager::load_game_config_for_create(bool is_mp, bool is_test) try{ load_game_config_with_loadscreen(NO_INCLUDE_RELOAD); } - catch(game::error&) { + catch(const game::error&) { cache_.clear_defines(); std::deque previous_defines; diff --git a/src/game_events/action_wml.cpp b/src/game_events/action_wml.cpp index 4e467bc82ded..1ed9f46ac14a 100644 --- a/src/game_events/action_wml.cpp +++ b/src/game_events/action_wml.cpp @@ -602,11 +602,11 @@ WML_HANDLER_FUNCTION(replace_map,, cfg) } else { map.read(cfg["map"], false); } - } catch(incorrect_map_format_error&) { + } catch(const incorrect_map_format_error&) { const std::string log_map_name = cfg["map"].empty() ? cfg["file"] : std::string("from inline data"); lg::wml_error() << "replace_map: Unable to load map " << log_map_name << std::endl; return; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { e.show(); return; } @@ -868,10 +868,10 @@ WML_HANDLER_FUNCTION(terrain_mask,, cfg) } else { mask_map.read(cfg["mask"], false); } - } catch(incorrect_map_format_error&) { + } catch(const incorrect_map_format_error&) { ERR_NG << "terrain mask is in the incorrect format, and couldn't be applied" << std::endl; return; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { e.show(); return; } diff --git a/src/game_initialization/create_engine.cpp b/src/game_initialization/create_engine.cpp index aee2e4e4d849..56b4e504a643 100644 --- a/src/game_initialization/create_engine.cpp +++ b/src/game_initialization/create_engine.cpp @@ -69,11 +69,11 @@ void scenario::set_metadata() try { map_.reset(new gamemap(game_config_manager::get()->terrain_types(), map_data)); - } catch(incorrect_map_format_error& e) { + } catch(const incorrect_map_format_error& e) { data_["description"] = _("Map could not be loaded: ") + e.message; ERR_CF << "map could not be loaded: " << e.message << '\n'; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { data_["description"] = _("Map could not be loaded."); ERR_CF << "map could not be loaded: " << e.dev_message << '\n'; @@ -335,7 +335,7 @@ void create_engine::init_generated_level_data() cur_lev->set_data(data); } - } catch (mapgen_exception & e) { + } catch (const mapgen_exception & e) { config data = cur_lev->data(); data["error_message"] = e.what(); @@ -520,7 +520,7 @@ void create_engine::set_current_level(const size_t index) { try { current_level_index_ = type_map_.at(current_level_type_.v).games_filtered.at(index); - } catch (std::out_of_range&) { + } catch (const std::out_of_range&) { current_level_index_ = 0u; } @@ -662,11 +662,11 @@ void create_engine::init_all_levels() std::unique_ptr map; try { map.reset(new gamemap(game_config_manager::get()->terrain_types(), user_map_data["map_data"])); - } catch (incorrect_map_format_error& e) { + } catch (const incorrect_map_format_error& e) { user_map_data["description"] = _("Map could not be loaded: ") + e.message; ERR_CF << "map could not be loaded: " << e.message << '\n'; - } catch (wml_exception&) { + } catch (const wml_exception&) { add_map = false; dep_index_offset++; } @@ -689,7 +689,7 @@ void create_engine::init_all_levels() config data; try { read(data, *preprocess_file(filesystem::get_user_data_dir() + "/editor/scenarios/" + user_scenario_names_[i])); - } catch (config::error & e) { + } catch(const config::error & e) { ERR_CF << "Caught a config error while parsing user made (editor) scenarios:\n" << e.message << std::endl; ERR_CF << "Skipping file: " << (filesystem::get_user_data_dir() + "/editor/scenarios/" + user_scenario_names_[i]) << std::endl; continue; diff --git a/src/game_initialization/lobby_data.cpp b/src/game_initialization/lobby_data.cpp index ae96e5239888..87de1e97a57c 100644 --- a/src/game_initialization/lobby_data.cpp +++ b/src/game_initialization/lobby_data.cpp @@ -314,9 +314,9 @@ game_info::game_info(const config& game, const config& game_config, const std::v msi << map.w() << font::unicode_multiplication_sign << map.h(); map_size_info = msi.str(); info_stream << spaced_em_dash() << map_size_info; - } catch(incorrect_map_format_error&) { + } catch(const incorrect_map_format_error&) { verified = false; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { ERR_CF << "map could not be loaded: " << e.dev_message << '\n'; verified = false; } diff --git a/src/game_initialization/lobby_info.cpp b/src/game_initialization/lobby_info.cpp index 744bd18ab1ec..f00c667f1c39 100644 --- a/src/game_initialization/lobby_info.cpp +++ b/src/game_initialization/lobby_info.cpp @@ -138,7 +138,7 @@ bool lobby_info::process_gamelist_diff(const config& data) try { gamelist_.apply_diff(data, true); - } catch(config::error& e) { + } catch(const config::error& e) { ERR_LB << "Error while applying the gamelist diff: '" << e.message << "' Getting a new gamelist.\n"; return false; } @@ -188,7 +188,7 @@ bool lobby_info::process_gamelist_diff(const config& data) try { gamelist_.clear_diff_track(data); - } catch(config::error& e) { + } catch(const config::error& e) { ERR_LB << "Error while applying the gamelist diff (2): '" << e.message << "' Getting a new gamelist.\n"; return false; } diff --git a/src/game_initialization/multiplayer.cpp b/src/game_initialization/multiplayer.cpp index 4920d717627e..5880773bad5c 100644 --- a/src/game_initialization/multiplayer.cpp +++ b/src/game_initialization/multiplayer.cpp @@ -268,7 +268,7 @@ std::pair open_connection(std::string host) if(outer_salt.size() != 32) throw utils::hash_error("salt wrong size"); sp["password"] = utils::md5(hash.base64_digest(), outer_salt).base64_digest(); - } catch(utils::hash_error& err) { + } catch(const utils::hash_error& err) { ERR_MP << "bcrypt hash failed: " << err.what() << std::endl; throw wesnothd_error(_("Bad data received from server")); } @@ -542,7 +542,7 @@ bool enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vectorgame_config(), game_config_manager::get()->terrain_types()); ccontroller.play_game(); - } catch (savegame::load_game_exception &e) { + } catch(const savegame::load_game_exception &e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); return true; } @@ -526,7 +526,7 @@ int game_launcher::unit_test() if (!(res == LEVEL_RESULT::VICTORY) || lg::broke_strict()) { return 1; } - } catch(wml_exception& e) { + } catch(const wml_exception& e) { std::cerr << "Caught WML Exception:" << e.dev_message << std::endl; return 1; } @@ -553,7 +553,7 @@ int game_launcher::unit_test() std::cerr << "Observed failure on replay" << std::endl; return 4; } - } catch(wml_exception& e) { + } catch(const wml_exception& e) { std::cerr << "WML Exception while playing replay: " << e.dev_message << std::endl; return 4; //failed with an error during the replay } @@ -588,7 +588,7 @@ bool game_launcher::play_render_image_mode() try { game_config_manager::get()-> load_game_config_for_game(state_.classification()); - } catch(config::error& e) { + } catch(const config::error& e) { std::cerr << "Error loading game config: " << e.what() << std::endl; return false; } @@ -633,13 +633,13 @@ bool game_launcher::load_game() try { game_config_manager::get()-> load_game_config_for_game(state_.classification()); - } catch(config::error&) { + } catch(const config::error&) { return false; } load.set_gamestate(); - } catch(config::error& e) { + } catch(const config::error& e) { if(e.message.empty()) { gui2::show_error_message(_("The file you have tried to load is corrupt")); } @@ -647,17 +647,17 @@ bool game_launcher::load_game() gui2::show_error_message(_("The file you have tried to load is corrupt: '") + e.message + '\''); } return false; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { e.show(); return false; - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { if(e.message.empty()) { gui2::show_error_message(_("File I/O Error while reading the game")); } else { gui2::show_error_message(_("File I/O Error while reading the game: '") + e.message + '\''); } return false; - } catch(game::error& e) { + } catch(const game::error& e) { if(e.message.empty()) { gui2::show_error_message(_("The file you have tried to load is corrupt")); } @@ -810,13 +810,13 @@ bool game_launcher::play_multiplayer(mp_selection res) { try { start_wesnothd(); - } catch(game::mp_server_error&) + } catch(const game::mp_server_error&) { preferences::show_wesnothd_server_search(); try { start_wesnothd(); - } catch(game::mp_server_error&) + } catch(const game::mp_server_error&) { return false; } @@ -854,22 +854,22 @@ bool game_launcher::play_multiplayer(mp_selection res) multiplayer_server_.clear(); } - } catch(wesnothd_rejected_client_error& e) { + } catch(const wesnothd_rejected_client_error& e) { gui2::show_error_message(e.message); - } catch(game::mp_server_error& e) { + } catch(const game::mp_server_error& e) { gui2::show_error_message(_("Error while starting server: ") + e.message); - } catch(game::load_game_failed& e) { + } catch(const game::load_game_failed& e) { gui2::show_error_message(_("The game could not be loaded: ") + e.message); - } catch(game::game_error& e) { + } catch(const game::game_error& e) { gui2::show_error_message(_("Error while playing the game: ") + e.message); - } catch (mapgen_exception& e) { + } catch (const mapgen_exception& e) { gui2::show_error_message(_("Map generator error: ") + e.message); - } catch(wesnothd_error& e) { + } catch(const wesnothd_error& e) { if(!e.message.empty()) { ERR_NET << "caught network error: " << e.message << std::endl; std::string user_msg; - auto conn_err = dynamic_cast(&e); + auto conn_err = dynamic_cast(&e); if(conn_err) { // The wesnothd_connection_error subclass is only thrown with messages @@ -890,21 +890,21 @@ bool game_launcher::play_multiplayer(mp_selection res) } else { ERR_NET << "caught network error" << std::endl; } - } catch(config::error& e) { + } catch(const config::error& e) { if(!e.message.empty()) { ERR_CONFIG << "caught config::error: " << e.message << std::endl; gui2::show_transient_message("", e.message); } else { ERR_CONFIG << "caught config::error" << std::endl; } - } catch(incorrect_map_format_error& e) { + } catch(const incorrect_map_format_error& e) { gui2::show_error_message(_("The game map could not be loaded: ") + e.message); - } catch (savegame::load_game_exception & e) { + } catch (const savegame::load_game_exception & e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded - } catch(wml_exception& e) { + } catch(const wml_exception& e) { e.show(); - } catch (game::error & e) { + } catch (const game::error & e) { std::cerr << "caught game::error...\n"; gui2::show_error_message(_("Error: ") + e.message); } @@ -970,7 +970,7 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload) try { game_config_manager::get()-> load_game_config_for_game(state_.classification()); - } catch(config::error&) { + } catch(const config::error&) { return; } } @@ -991,12 +991,12 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload) gui2::dialogs::end_credits::display(state_.classification().campaign); } } - } catch (savegame::load_game_exception &e) { + } catch (const savegame::load_game_exception &e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded - } catch(wml_exception& e) { + } catch(const wml_exception& e) { e.show(); - } catch(mapgen_exception& e) { + } catch(const mapgen_exception& e) { gui2::show_error_message(_("Map generator error: ") + e.message); } } @@ -1007,10 +1007,10 @@ void game_launcher::play_replay() try { campaign_controller ccontroller(state_, game_config_manager::get()->game_config(), game_config_manager::get()->terrain_types()); ccontroller.play_replay(); - } catch (savegame::load_game_exception &e) { + } catch (const savegame::load_game_exception &e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded - } catch(wml_exception& e) { + } catch(const wml_exception& e) { e.show(); } } diff --git a/src/generators/cave_map_generator.cpp b/src/generators/cave_map_generator.cpp index 4bd760d93e72..501fabbe37b5 100644 --- a/src/generators/cave_map_generator.cpp +++ b/src/generators/cave_map_generator.cpp @@ -161,7 +161,7 @@ void cave_map_generator::cave_map_generator_job::generate_chambers() try { min_xpos = std::stoi(items.front()) - 1; max_xpos = std::stoi(items.back()); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { lg::wml_error() << "Invalid min/max coordinates in cave_map_generator: " << items.front() << ", " << items.back() << "\n"; continue; } @@ -174,7 +174,7 @@ void cave_map_generator::cave_map_generator_job::generate_chambers() try { min_ypos = std::stoi(items.front()) - 1; max_ypos = std::stoi(items.back()); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { lg::wml_error() << "Invalid min/max coordinates in cave_map_generator: " << items.front() << ", " << items.back() << "\n"; } } diff --git a/src/generators/default_map_generator.cpp b/src/generators/default_map_generator.cpp index 8c517220d099..7c6acbc7ba33 100644 --- a/src/generators/default_map_generator.cpp +++ b/src/generators/default_map_generator.cpp @@ -147,7 +147,7 @@ std::string default_map_generator::generate_map(std::map randomse try{ res["map_data"] = generate_map(&labels, randomseed); } - catch (mapgen_exception& exc){ + catch (const mapgen_exception& exc){ res["map_data"] = ""; res["error_message"] = exc.message; } diff --git a/src/generators/lua_map_generator.cpp b/src/generators/lua_map_generator.cpp index 64a647029a9c..41f1361cb5db 100644 --- a/src/generators/lua_map_generator.cpp +++ b/src/generators/lua_map_generator.cpp @@ -49,7 +49,7 @@ void lua_map_generator::user_config() { try { lk_.user_config(user_config_.c_str(), generator_data_); - } catch (game::lua_error & e) { + } catch(const game::lua_error & e) { std::string msg = "Error when running lua_map_generator user_config.\n"; msg += "The generator was: " + config_name_ + "\n"; msg += e.what(); @@ -65,7 +65,7 @@ std::string lua_map_generator::create_map(boost::optional seed) try { return lk_.create_map(create_map_.c_str(), generator_data_, seed); - } catch (game::lua_error & e) { + } catch (const game::lua_error & e) { std::string msg = "Error when running lua_map_generator create_map.\n"; msg += "The generator was: " + config_name_ + "\n"; msg += e.what(); @@ -81,7 +81,7 @@ config lua_map_generator::create_scenario(boost::optional seed) try { return lk_.create_scenario(create_scenario_.c_str(), generator_data_, seed); - } catch (game::lua_error & e) { + } catch (const game::lua_error & e) { std::string msg = "Error when running lua_map_generator create_scenario.\n"; msg += "The generator was: " + config_name_ + "\n"; msg += e.what(); diff --git a/src/gettext_boost.cpp b/src/gettext_boost.cpp index dd72e06c7c98..3e18948e37eb 100644 --- a/src/gettext_boost.cpp +++ b/src/gettext_boost.cpp @@ -138,9 +138,9 @@ namespace po_file.open(path); const po_catalog& cat = po_catalog::from_istream(po_file); extra_messages_.emplace(get_base().domain(domain), cat); - } catch(spirit_po::catalog_exception& e) { + } catch(const spirit_po::catalog_exception& e) { throw_po_error(lang_name_long, domain, e.what()); - } catch(std::ios::failure&) { + } catch(const std::ios::failure&) { throw_po_error(lang_name_long, domain, strerror(errno)); } } diff --git a/src/gui/dialogs/advanced_graphics_options.cpp b/src/gui/dialogs/advanced_graphics_options.cpp index dc1d158117e4..aaacec179c06 100644 --- a/src/gui/dialogs/advanced_graphics_options.cpp +++ b/src/gui/dialogs/advanced_graphics_options.cpp @@ -54,7 +54,7 @@ advanced_graphics_options::SCALING_ALGORITHM advanced_graphics_options::get_scal try { algo = SCALING_ALGORITHM::string_to_enum(preferences::get(pref_id)); - } catch(bad_enum_cast&) { + } catch(const bad_enum_cast&) { preferences::set(pref_id, algo.to_string()); } diff --git a/src/gui/dialogs/editor/custom_tod.cpp b/src/gui/dialogs/editor/custom_tod.cpp index 8e3615976734..dbf88517138e 100644 --- a/src/gui/dialogs/editor/custom_tod.cpp +++ b/src/gui/dialogs/editor/custom_tod.cpp @@ -257,7 +257,7 @@ const time_of_day& custom_tod::get_selected_tod() const { try { return times_.at(current_tod_); - } catch(std::out_of_range&) { + } catch(const std::out_of_range&) { throw std::string("Attempted to fetch a non-existant ToD!"); } } diff --git a/src/gui/dialogs/game_load.cpp b/src/gui/dialogs/game_load.cpp index 5e17c2f8209c..1bc5ddf79677 100644 --- a/src/gui/dialogs/game_load.cpp +++ b/src/gui/dialogs/game_load.cpp @@ -343,7 +343,7 @@ void game_load::evaluate_summary_string(std::stringstream& str, const config& cf str << _("Test scenario"); break; } - } catch(bad_enum_cast&) { + } catch(const bad_enum_cast&) { str << campaign_type; } diff --git a/src/gui/dialogs/lua_interpreter.cpp b/src/gui/dialogs/lua_interpreter.cpp index 423d8af6b5cf..6086f640ca83 100644 --- a/src/gui/dialogs/lua_interpreter.cpp +++ b/src/gui/dialogs/lua_interpreter.cpp @@ -420,7 +420,7 @@ bool lua_interpreter::lua_model::execute (const std::string & cmd) try { L_.interactive_run(cmd.c_str()); return true; - } catch (game::lua_error & e) { + } catch (const game::lua_error & e) { add_dialog_message(std::string(e.what())); return false; } diff --git a/src/gui/dialogs/multiplayer/lobby.cpp b/src/gui/dialogs/multiplayer/lobby.cpp index 2062e7f75d41..5fb5c9a01ae4 100644 --- a/src/gui/dialogs/multiplayer/lobby.cpp +++ b/src/gui/dialogs/multiplayer/lobby.cpp @@ -864,7 +864,7 @@ void mp_lobby::network_handler() if (network_connection_.receive_data(data)) { process_network_data(data); } - } catch (wesnothd_error& e) { + } catch (const wesnothd_error& e) { LOG_LB << "caught wesnothd_error in network_handler: " << e.message << "\n"; throw; } diff --git a/src/gui/dialogs/preferences_dialog.cpp b/src/gui/dialogs/preferences_dialog.cpp index c9f697bc1eb4..178696fef914 100644 --- a/src/gui/dialogs/preferences_dialog.cpp +++ b/src/gui/dialogs/preferences_dialog.cpp @@ -603,7 +603,7 @@ void preferences_dialog::post_build(window& window) ADVANCED_PREF_TYPE pref_type; try { pref_type = ADVANCED_PREF_TYPE::string_to_enum(option["type"].str()); - } catch(bad_enum_cast&) { + } catch(const bad_enum_cast&) { continue; } diff --git a/src/gui/dialogs/story_viewer.hpp b/src/gui/dialogs/story_viewer.hpp index b98687f80707..f441539ca9bc 100644 --- a/src/gui/dialogs/story_viewer.hpp +++ b/src/gui/dialogs/story_viewer.hpp @@ -42,7 +42,7 @@ class story_viewer : public modal_dialog if(viewer.controller_.max_parts() > 0) { viewer.show(); } - } catch(std::out_of_range&) {} + } catch(const std::out_of_range&) {} } private: diff --git a/src/gui/dialogs/title_screen.cpp b/src/gui/dialogs/title_screen.cpp index 33c7194bf6d2..5a8ac6158d1d 100644 --- a/src/gui/dialogs/title_screen.cpp +++ b/src/gui/dialogs/title_screen.cpp @@ -371,7 +371,7 @@ void title_screen::pre_show(window& win) ::image::flush_cache(); on_resize(win); } - } catch(std::runtime_error& e) { + } catch(const std::runtime_error& e) { gui2::show_error_message(e.what()); } }); diff --git a/src/gui/dialogs/tooltip.cpp b/src/gui/dialogs/tooltip.cpp index 437ac247c71b..f1eb4cca9208 100644 --- a/src/gui/dialogs/tooltip.cpp +++ b/src/gui/dialogs/tooltip.cpp @@ -169,7 +169,7 @@ void show(const std::string& window_id, { t.show(); } - catch(window_builder_invalid_id&) + catch(const window_builder_invalid_id&) { ERR_CFG << "Tip with the requested id '" << window_id << "' doesn't exist, fall back to the default.\n"; @@ -178,7 +178,7 @@ void show(const std::string& window_id, { t.show(); } - catch(window_builder_invalid_id&) + catch(const window_builder_invalid_id&) { ERR_CFG << "Default tooltip doesn't exist, no message shown." << std::endl; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 7ceda9c17fdf..27c14cfe3733 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -54,7 +54,7 @@ void init() filesystem::scoped_istream stream = preprocess_file(filesystem::get_wml_location("gui/_main.cfg"), &preproc); read(cfg, *stream, &validator); - } catch(config::error& e) { + } catch(const config::error& e) { ERR_GUI_P << e.what() << '\n'; ERR_GUI_P << "Setting: could not read file 'data/gui/_main.cfg'." << std::endl; } catch(const abstract_validator::error& e) { diff --git a/src/gui/widgets/minimap.cpp b/src/gui/widgets/minimap.cpp index 98a653cd4788..063bc3d051a8 100644 --- a/src/gui/widgets/minimap.cpp +++ b/src/gui/widgets/minimap.cpp @@ -218,7 +218,7 @@ const surface minimap::get_image(const int w, const int h) const #endif return surf; } - catch(incorrect_map_format_error& e) + catch(const incorrect_map_format_error& e) { ERR_CF << "Error while loading the map: " << e.message << '\n'; #ifdef DEBUG_MINIMAP_CACHE diff --git a/src/gui/widgets/size_lock.cpp b/src/gui/widgets/size_lock.cpp index d2c6cc1efda2..e828d4754e3f 100644 --- a/src/gui/widgets/size_lock.cpp +++ b/src/gui/widgets/size_lock.cpp @@ -47,7 +47,7 @@ void size_lock::place(const point& origin, const point& size) if(content_size.y > size.y) { try { reduce_height(size.y); - } catch(layout_exception_width_modified&) { + } catch(const layout_exception_width_modified&) { } content_size = widget_->get_best_size(); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 2118b7e3278a..5df58798a3fc 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -949,7 +949,7 @@ void window::layout() { window_implementation::layout(*this, maximum_width, maximum_height); } - catch(layout_exception_resize_failed&) + catch(const layout_exception_resize_failed&) { /** @todo implement the scrollbars on the window. */ @@ -985,7 +985,7 @@ void window::layout() window_implementation::layout( *this, maximum_width, maximum_height); } - catch(layout_exception_resize_failed&) + catch(const layout_exception_resize_failed&) { /** @todo implement the scrollbars on the window. */ @@ -1261,7 +1261,7 @@ void window_implementation::layout(window& window, DBG_GUI_L << LOG_IMPL_HEADER << " Result: Resizing succeeded.\n"; return; } - catch(layout_exception_width_modified&) + catch(const layout_exception_width_modified&) { DBG_GUI_L << LOG_IMPL_HEADER << " Status: Width has been modified, rerun.\n"; diff --git a/src/halo.cpp b/src/halo.cpp index f742f576f4ee..de93d038aa13 100644 --- a/src/halo.cpp +++ b/src/halo.cpp @@ -318,7 +318,7 @@ int halo_impl::add(int x, int y, const std::string& image, const map_location& l str = sub_items.front(); try { time = std::stoi(sub_items.back()); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_DP << "Invalid time value found when constructing halo: " << sub_items.back() << "\n"; } } diff --git a/src/image.cpp b/src/image.cpp index 6f0999a943d3..fef85af7e42f 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -1340,7 +1340,7 @@ bool update_from_preferences() SCALING_ALGORITHM algo = preferences::default_scaling_algorithm; try { algo = SCALING_ALGORITHM::string_to_enum(preferences::get("scale_hex")); - } catch(bad_enum_cast&) { + } catch(const bad_enum_cast&) { } scale_to_hex_func = select_algorithm(algo); @@ -1348,7 +1348,7 @@ bool update_from_preferences() algo = preferences::default_scaling_algorithm; try { algo = SCALING_ALGORITHM::string_to_enum(preferences::get("scale_zoom")); - } catch(bad_enum_cast&) { + } catch(const bad_enum_cast&) { } scale_to_zoom_func = select_algorithm(algo); diff --git a/src/image_modifications.cpp b/src/image_modifications.cpp index 76fff988e1a4..89bf1d4ba54a 100644 --- a/src/image_modifications.cpp +++ b/src/image_modifications.cpp @@ -702,7 +702,7 @@ REGISTER_MOD_PARSER(RC, args) const std::vector& old_color = game_config::tc_info(recolor_params[0]); rc_map = recolor_range(new_color,old_color); - } catch (config::error& e) { + } catch (const config::error& e) { ERR_DP << "caught config::error while processing color-range RC: " << e.message @@ -736,7 +736,7 @@ REGISTER_MOD_PARSER(PAL, args) } return new rc_modification(rc_map); - } catch(config::error& e) { + } catch(const config::error& e) { ERR_DP << "caught config::error while processing PAL function: " << e.message @@ -810,7 +810,7 @@ REGISTER_MOD_PARSER(BW, args) } else { return new bw_modification(threshold); } - } catch (std::invalid_argument&) { + } catch (const std::invalid_argument&) { ERR_DP << "unsupported argument in ~BW() function" << std::endl; return nullptr; } @@ -843,7 +843,7 @@ REGISTER_MOD_PARSER(NEG, args) } else { return new negative_modification(threshold, threshold, threshold); } - } catch (std::invalid_argument&) { + } catch (const std::invalid_argument&) { ERR_DP << "unsupported argument value in ~NEG() function" << std::endl; return nullptr; } @@ -859,7 +859,7 @@ REGISTER_MOD_PARSER(NEG, args) } else { return new negative_modification(thresholdRed, thresholdGreen, thresholdBlue); } - } catch (std::invalid_argument&) { + } catch (const std::invalid_argument&) { ERR_DP << "unsupported argument value in ~NEG() function" << std::endl; return nullptr; } diff --git a/src/language.cpp b/src/language.cpp index c193351699ed..c597fc4c1987 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -95,7 +95,7 @@ bool load_language_list() try { filesystem::scoped_istream stream = preprocess_file(filesystem::get_wml_location("hardwired/language.cfg")); read(cfg, *stream); - } catch(config::error &) { + } catch(const config::error &) { return false; } diff --git a/src/language.hpp b/src/language.hpp index a2a607891572..46714ee96c0a 100644 --- a/src/language.hpp +++ b/src/language.hpp @@ -44,7 +44,7 @@ struct language_def { try { this->percent = percent.empty() ? 100 : std::stoi(percent); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { this->percent = 100; } } diff --git a/src/lexical_cast.hpp b/src/lexical_cast.hpp index 4f809d879df5..00af54ab322d 100644 --- a/src/lexical_cast.hpp +++ b/src/lexical_cast.hpp @@ -230,8 +230,8 @@ struct lexical_caster< try { return std::stoll(value); - } catch(std::invalid_argument&) { - } catch(std::out_of_range&) { + } catch(const std::invalid_argument&) { + } catch(const std::out_of_range&) { } if(fallback) { @@ -288,8 +288,8 @@ struct lexical_caster< if(std::numeric_limits::lowest() <= res && std::numeric_limits::max() >= res) { return static_cast(res); } - } catch(std::invalid_argument&) { - } catch(std::out_of_range&) { + } catch(const std::invalid_argument&) { + } catch(const std::out_of_range&) { } if(fallback) { @@ -355,8 +355,8 @@ struct lexical_caster< if((static_cast(std::numeric_limits::lowest()) <= res) && (static_cast(std::numeric_limits::max()) >= res)) { return static_cast(res); } - } catch(std::invalid_argument&) { - } catch(std::out_of_range&) { + } catch(const std::invalid_argument&) { + } catch(const std::out_of_range&) { } if(fallback) { @@ -414,8 +414,8 @@ struct lexical_caster< try { return std::stoull(value); - } catch(std::invalid_argument&) { - } catch(std::out_of_range&) { + } catch(const std::invalid_argument&) { + } catch(const std::out_of_range&) { } if(fallback) { @@ -473,8 +473,8 @@ struct lexical_caster< if(std::numeric_limits::max() >= res) { return static_cast(res); } - } catch(std::invalid_argument&) { - } catch(std::out_of_range&) { + } catch(const std::invalid_argument&) { + } catch(const std::out_of_range&) { } if(fallback) { diff --git a/src/map/label.cpp b/src/map/label.cpp index 215955dd46d1..82cbbd307db5 100644 --- a/src/map/label.cpp +++ b/src/map/label.cpp @@ -417,7 +417,7 @@ void terrain_label::read(const config& cfg) if(!tmp_color.empty()) { try { color = color_t::from_rgb_string(tmp_color); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { // Prior to the color_t conversion, labels were written to savefiles with an alpha key, despite alpha not // being accepted in color=. Because of this, this enables the loading of older saves without an exception // throwing. diff --git a/src/map/location.cpp b/src/map/location.cpp index cb58b8348a70..7d770f6f2a17 100644 --- a/src/map/location.cpp +++ b/src/map/location.cpp @@ -193,7 +193,7 @@ map_location::map_location(const config& cfg, const variable_set *variables) : if(xs.empty() == false && xs != "recall") { try { x = std::stoi(xs) - 1; - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_CF << "Invalid map coordinate: " << xs << "\n"; } } @@ -201,7 +201,7 @@ map_location::map_location(const config& cfg, const variable_set *variables) : if(ys.empty() == false && ys != "recall") {\ try { y = std::stoi(ys) - 1; - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_CF << "Invalid map coordinate: " << ys << "\n"; } } @@ -345,7 +345,7 @@ bool map_location::matches_range(const std::string& xloc, const std::string &ylo try { bot = std::stoi(beg) - 1; top = std::stoi(end) - 1; - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_CF << "Invalid map coordinate: " << end << ", " << beg << "\n"; } @@ -356,7 +356,7 @@ bool map_location::matches_range(const std::string& xloc, const std::string &ylo try { xval = std::stoi(xloc) - 1; - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_CF << "Invalid map coordinate: " << xloc << "\n"; } @@ -377,7 +377,7 @@ bool map_location::matches_range(const std::string& xloc, const std::string &ylo try { bot = std::stoi(beg) - 1; top = std::stoi(end) - 1; - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_CF << "Invalid map coordinate: " << end << ", " << beg << "\n"; } @@ -388,7 +388,7 @@ bool map_location::matches_range(const std::string& xloc, const std::string &ylo try { yval = std::stoi(yloc) - 1; - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_CF << "Invalid map coordinate: " << yloc << "\n"; } diff --git a/src/map/map.cpp b/src/map/map.cpp index 1f6bf1de602c..268d0bb39e3f 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -137,7 +137,7 @@ void gamemap::read(const std::string& data, const bool allow_invalid) try { tiles_ = t_translation::read_game_map(data_only, starting_positions_, t_translation::coordinate{ border_size(), border_size() }); - } catch(t_translation::error& e) { + } catch(const t_translation::error& e) { // We re-throw the error but as map error. // Since all codepaths test for this, it's the least work. throw incorrect_map_format_error(e.message); diff --git a/src/menu_events.cpp b/src/menu_events.cpp index 16c7b4ccec2c..1f4349485099 100644 --- a/src/menu_events.cpp +++ b/src/menu_events.cpp @@ -188,7 +188,7 @@ void menu_handler::save_map() try { filesystem::write_file(dlg.path(), map().write()); gui2::show_transient_message("", _("Map saved.")); - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { utils::string_map symbols; symbols["msg"] = e.what(); const std::string msg = VGETTEXT("Could not save the map: $msg", symbols); @@ -1518,7 +1518,7 @@ void console_handler::do_control() unsigned int side_num; try { side_num = lexical_cast(side); - } catch(bad_lexical_cast&) { + } catch(const bad_lexical_cast&) { const auto it_t = std::find_if( resources::gameboard->teams().begin(), resources::gameboard->teams().end(), save_id_matches(side)); if(it_t == resources::gameboard->teams().end()) { @@ -1548,7 +1548,7 @@ void console_handler::do_controller() unsigned int side_num; try { side_num = lexical_cast(side); - } catch(bad_lexical_cast&) { + } catch(const bad_lexical_cast&) { utils::string_map symbols; symbols["side"] = side; command_failed(VGETTEXT("Can't query control of invalid side: '$side'.", symbols)); @@ -1957,7 +1957,7 @@ void menu_handler::do_ai_formula(const std::string& str, int side_num, mouse_han { try { add_chat_message(time(nullptr), "wfl", 0, ai::manager::get_singleton().evaluate_command(side_num, str)); - } catch(wfl::formula_error&) { + } catch(const wfl::formula_error&) { } catch(...) { add_chat_message(time(nullptr), "wfl", 0, "UNKNOWN ERROR IN FORMULA"); } diff --git a/src/mouse_events.cpp b/src/mouse_events.cpp index 659efd3306b3..3950d8fbb6c3 100644 --- a/src/mouse_events.cpp +++ b/src/mouse_events.cpp @@ -1011,7 +1011,7 @@ void mouse_handler::attack_enemy(const map_location& attacker_loc, const map_loc { try { attack_enemy_(attacker_loc, defender_loc, choice); - } catch(std::bad_alloc&) { + } catch(const std::bad_alloc&) { lg::wml_error() << "Memory exhausted a unit has either a lot hitpoints or a negative amount.\n"; } } diff --git a/src/persist_context.cpp b/src/persist_context.cpp index 7fabc3ed6374..95229d43d16f 100644 --- a/src/persist_context.cpp +++ b/src/persist_context.cpp @@ -39,7 +39,7 @@ void persist_file_context::load() if (!(file_stream->fail())) { try { read(cfg_,*file_stream); - } catch (config::error &err) { + } catch (const config::error &err) { LOG_PERSIST << err.message << std::endl; } } diff --git a/src/playmp_controller.cpp b/src/playmp_controller.cpp index c08ab8eaaddc..26b6302127df 100644 --- a/src/playmp_controller.cpp +++ b/src/playmp_controller.cpp @@ -251,11 +251,11 @@ void playmp_controller::linger() play_linger_turn(); after_human_turn(); LOG_NG << "finished human turn" << std::endl; - } catch (savegame::load_game_exception&) { + } catch (const savegame::load_game_exception&) { LOG_NG << "caught load-game-exception" << std::endl; // this should not happen, the option to load a game is disabled throw; - } catch (ingame_wesnothd_error&) { + } catch (const ingame_wesnothd_error&) { LOG_NG << "caught network-error-exception" << std::endl; quit = false; } diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index 28f3135d3f82..0b29f62f37f1 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -247,7 +247,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level) try { soundsource::sourcespec spec(s); soundsources_manager_->add(spec); - } catch (bad_lexical_cast &) { + } catch (const bad_lexical_cast &) { ERR_NG << "Error when parsing sound_source config: bad lexical cast." << std::endl; ERR_NG << "sound_source config was: " << s.debug() << std::endl; ERR_NG << "Skipping this sound source..." << std::endl; @@ -332,12 +332,12 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level) // Loading a new game is effectively a quit. saved_game_.clear(); throw; - } catch(wesnothd_error& e) { + } catch(const wesnothd_error& e) { scoped_savegame_snapshot snapshot(*this); savegame::ingame_savegame save(saved_game_, preferences::save_compression_format()); save.save_game_interactive(_("A network disconnection has occurred, and the game cannot continue. Do you want to save the game?"), savegame::savegame::YES_NO); - if(dynamic_cast(&e)) { + if(dynamic_cast(&e)) { return LEVEL_RESULT::QUIT; } else { throw; @@ -543,9 +543,9 @@ void playsingle_controller::play_ai_turn() ai::manager::get_singleton().play_turn(current_side()); } } - catch (return_to_play_side_exception&) { + catch (const return_to_play_side_exception&) { } - catch (fallback_ai_to_human_exception&) { + catch (const fallback_ai_to_human_exception&) { current_team().make_human(); player_type_changed_ = true; ai_fallback_ = true; diff --git a/src/preferences/credentials.cpp b/src/preferences/credentials.cpp index 5dd686c0f741..50eae19bd66e 100644 --- a/src/preferences/credentials.cpp +++ b/src/preferences/credentials.cpp @@ -233,7 +233,7 @@ namespace preferences filesystem::scoped_ostream credentials_file = filesystem::ostream_file(filesystem::get_credentials_file()); secure_buffer encrypted = encrypt(credentials_data, build_key("global", get_system_username())); credentials_file->write(reinterpret_cast(encrypted.data()), encrypted.size()); - } catch(filesystem::io_exception&) { + } catch(const filesystem::io_exception&) { ERR_CFG << "error writing to credentials file '" << filesystem::get_credentials_file() << "'" << std::endl; } } diff --git a/src/preferences/general.cpp b/src/preferences/general.cpp index f3ac0fd4cb18..492c192447c6 100644 --- a/src/preferences/general.cpp +++ b/src/preferences/general.cpp @@ -160,7 +160,7 @@ void write_preferences() try { filesystem::scoped_ostream prefs_file = filesystem::ostream_file(filesystem::get_prefs_file()); write(*prefs_file, prefs); - } catch(filesystem::io_exception&) { + } catch(const filesystem::io_exception&) { ERR_FS << "error writing to preferences file '" << filesystem::get_prefs_file() << "'" << std::endl; } diff --git a/src/replay.cpp b/src/replay.cpp index 714c24b49a3c..e2a0bbbfda96 100644 --- a/src/replay.cpp +++ b/src/replay.cpp @@ -460,7 +460,7 @@ static bool fix_rename_command(const config& c, config& async_child) try { read_locations(child,steps); - } catch (bad_lexical_cast &) { + } catch(const bad_lexical_cast &) { WRN_REPLAY << "Warning: Path data contained something which could not be parsed to a sequence of locations:" << "\n config = " << child.debug() << std::endl; } diff --git a/src/save_blocker.cpp b/src/save_blocker.cpp index b09c7a09af9a..521a1495d045 100644 --- a/src/save_blocker.cpp +++ b/src/save_blocker.cpp @@ -32,7 +32,7 @@ save_blocker::~save_blocker() { controller_ = nullptr; callback_ = nullptr; } - } catch (std::exception & e) { + } catch (const std::exception & e) { std::cerr << "Save blocker dtor swallowing an exception: " << e.what() << "\n"; } } diff --git a/src/save_index.cpp b/src/save_index.cpp index 26c7a912a4f8..afad1839f573 100644 --- a/src/save_index.cpp +++ b/src/save_index.cpp @@ -59,7 +59,7 @@ void save_index_class::rebuild(const std::string& name, const time_t& modified) read_save_file(name, full, &dummy); extract_summary_from_config(full, summary); - } catch(game::load_game_failed&) { + } catch(const game::load_game_failed&) { summary["corrupt"] = true; } @@ -105,7 +105,7 @@ void save_index_class::write_save_index() } else { write(*stream, data()); } - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { ERR_SAVE << "error writing to save index file: '" << e.what() << "'" << std::endl; } } @@ -140,13 +140,13 @@ config& save_index_class::data() filesystem::scoped_istream stream = filesystem::istream_file(si_file); try { read_gz(data_, *stream); - } catch(boost::iostreams::gzip_error&) { + } catch(const boost::iostreams::gzip_error&) { stream->seekg(0); read(data_, *stream); } - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { ERR_SAVE << "error reading save index: '" << e.what() << "'" << std::endl; - } catch(config::error& e) { + } catch(const config::error& e) { ERR_SAVE << "error parsing save index config file:\n" << e.message << std::endl; data_.clear(); } diff --git a/src/savegame.cpp b/src/savegame.cpp index 288a9101952f..2fc4bdf697ff 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -190,7 +190,7 @@ bool loadgame::load_game() gui2::show_error_message( _("Warning: The file you have tried to load is corrupt. Loading anyway.\n") + error_log); - } catch (utf8::invalid_utf8_exception&) { + } catch (const utf8::invalid_utf8_exception&) { gui2::show_error_message( _("Warning: The file you have tried to load is corrupt. Loading anyway.\n") + std::string("(UTF-8 ERROR)")); @@ -468,7 +468,7 @@ bool savegame::save_game(const std::string& filename) if (show_confirmation_) gui2::show_transient_message(_("Saved"), _("The game has been saved.")); return true; - } catch(game::save_game_failed& e) { + } catch(const game::save_game_failed& e) { ERR_SAVE << error_message_ << e.message << std::endl; gui2::show_error_message(error_message_ + e.message); @@ -519,7 +519,7 @@ void savegame::finish_save_game(const config_writer &out) throw game::save_game_failed(_("Could not write to file")); } save_index_manager.remove(gamestate_.classification().label); - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { throw game::save_game_failed(e.what()); } } @@ -529,7 +529,7 @@ filesystem::scoped_ostream savegame::open_save_game(const std::string &label) { try { return filesystem::ostream_file(filesystem::get_saves_dir() + "/" + label); - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { throw game::save_game_failed(e.what()); } } diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index bb422b09c0f7..33781d0ef8c3 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -3823,7 +3823,7 @@ int game_lua_kernel::intf_add_sound_source(lua_State *L) soundsource::sourcespec spec(cfg); man->add(spec); man->update(); - } catch (bad_lexical_cast &) { + } catch (const bad_lexical_cast &) { ERR_LUA << "Error when parsing sound_source config: invalid parameter." << std::endl; ERR_LUA << "sound_source config was: " << cfg.debug() << std::endl; ERR_LUA << "Skipping this sound source..." << std::endl; diff --git a/src/scripting/lua_kernel_base.cpp b/src/scripting/lua_kernel_base.cpp index a3058b9decb4..0a2db78cb905 100644 --- a/src/scripting/lua_kernel_base.cpp +++ b/src/scripting/lua_kernel_base.cpp @@ -726,7 +726,7 @@ void lua_kernel_base::run(const char * prog, int nArgs) { try { this->throwing_run(prog, nArgs); - } catch (game::lua_error & e) { + } catch (const game::lua_error & e) { cmd_log_ << e.what() << "\n"; lua_kernel_base::log_error(e.what(), "In function lua_kernel::run()"); } @@ -743,7 +743,7 @@ void lua_kernel_base::interactive_run(char const * prog) { try { // Try to load the experiment without syntax errors this->load_string(experiment.c_str(), eh); - } catch (game::lua_error &) { + } catch (const game::lua_error &) { this->throwing_run(prog, 0); // Since it failed, fall back to the usual throwing_run, on the original input. return; } diff --git a/src/serialization/preprocessor.cpp b/src/serialization/preprocessor.cpp index 7e80eba1a18a..55cfc75152e1 100644 --- a/src/serialization/preprocessor.cpp +++ b/src/serialization/preprocessor.cpp @@ -1225,7 +1225,7 @@ bool preprocessor_data::get_chunk() } else { deprecation_level = level; } - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { // Meh, fall back to default of PREEMPTIVE... deprecation_level = DEP_LEVEL::PREEMPTIVE; } @@ -1408,7 +1408,7 @@ bool preprocessor_data::get_chunk() DEP_LEVEL level = DEP_LEVEL::PREEMPTIVE; try { level = DEP_LEVEL(std::stoi(read_word())); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { // Meh, just fall back to the default of PREEMPTIVE... } version_info version = game_config::wesnoth_version; diff --git a/src/serialization/schema_validator.cpp b/src/serialization/schema_validator.cpp index b889076f5e75..7e67684f33d2 100644 --- a/src/serialization/schema_validator.cpp +++ b/src/serialization/schema_validator.cpp @@ -148,7 +148,7 @@ bool schema_validator::read_config_file(const std::string& filename) preproc_map preproc(game_config::config_cache::instance().get_preproc_map()); filesystem::scoped_istream stream = preprocess_file(filename, &preproc); read(cfg, *stream); - } catch(config::error& e) { + } catch(const config::error& e) { ERR_VL << "Failed to read file " << filename << ":\n" << e.what() << "\n"; return false; } @@ -164,7 +164,7 @@ bool schema_validator::read_config_file(const std::string& filename) for(const config& type : g.child_range("type")) { try { types_[type["name"].str()] = boost::regex(type["value"].str()); - } catch(std::exception&) { + } catch(const std::exception&) { // Need to check all type values in schema-generator } } diff --git a/src/serialization/string_utils.cpp b/src/serialization/string_utils.cpp index 5ca13b0284e2..d5c31aab58c8 100644 --- a/src/serialization/string_utils.cpp +++ b/src/serialization/string_utils.cpp @@ -417,7 +417,7 @@ int apply_modifier( const int number, const std::string &amount, const int minim int value = 0; try { value = std::stoi(amount); - } catch(std::invalid_argument&) {} + } catch(const std::invalid_argument&) {} if(amount[amount.size()-1] == '%') { value = div100rounded(number * value); } @@ -824,7 +824,7 @@ std::pair parse_range(const std::string& str) if (res.second < res.first) { res.second = res.first; } - } catch(std::invalid_argument&) {} + } catch(const std::invalid_argument&) {} return res; } diff --git a/src/serialization/unicode.cpp b/src/serialization/unicode.cpp index bf211a8ad83f..d53a146fbc21 100644 --- a/src/serialization/unicode.cpp +++ b/src/serialization/unicode.cpp @@ -77,7 +77,7 @@ size_t index(const utf8::string& str, const size_t index) for (unsigned int chr=0; chr::type unicode_ impl_writer::write (dst, impl_reader::read(i1, i2)); } } - catch(utf8::invalid_utf8_exception&) + catch(const utf8::invalid_utf8_exception&) { // TODO: use a ERR_.. stream but I don't know whether I can do so in header easily. std::cerr << "Failed to convert a string from " << impl_reader::get_name() << " to " << impl_writer::get_name() << "\n"; @@ -104,7 +104,7 @@ TD unicode_cast(ucs4::char_t onechar) iteratorwriter dst(inserter); impl_writer::write (dst, onechar); } - catch(utf8::invalid_utf8_exception&) + catch(const utf8::invalid_utf8_exception&) { // TODO: use a ERR_.. stream but I don't know whether I can do so in header easily. std::cerr << "Failed to convert a string from " << impl_reader::get_name() << " to " << impl_writer::get_name() << "\n"; diff --git a/src/server/ban.cpp b/src/server/ban.cpp index c1233ec495a6..c4713601564f 100644 --- a/src/server/ban.cpp +++ b/src/server/ban.cpp @@ -276,7 +276,7 @@ static lg::log_domain log_server("server"); if (new_ban->get_end_time() != 0) time_queue_.push(new_ban); - } catch (banned::error& e) { + } catch (const banned::error& e) { ERR_SERVER << e.message << " while reading bans" << std::endl; } } @@ -289,7 +289,7 @@ static lg::log_domain log_server("server"); try { banned_ptr new_ban(new banned(b)); deleted_bans_.push_back(new_ban); - } catch (banned::error& e) { + } catch (const banned::error& e) { ERR_SERVER << e.message << " while reading deleted bans" << std::endl; } } @@ -376,7 +376,7 @@ static lg::log_domain log_server("server"); std::string dur_lower; try { dur_lower = utf8::lowercase(duration); - } catch ( utf8::invalid_utf8_exception & e ) { + } catch (const utf8::invalid_utf8_exception & e ) { ERR_SERVER << "While parsing ban command duration string, caught an invalid utf8 exception: " << e.what() << std::endl; return false; } @@ -504,7 +504,7 @@ static lg::log_domain log_server("server"); ret << "Overwriting ban: " << (**ban) << "\n"; bans_.erase(ban); } - } catch (banned::error& e) { + } catch (const banned::error& e) { ERR_SERVER << e.message << " while creating dummy ban for finding existing ban" << std::endl; return e.message; } @@ -514,7 +514,7 @@ static lg::log_domain log_server("server"); if (end_time != 0) time_queue_.push(new_ban); ret << *new_ban; - } catch (banned::error& e) { + } catch (const banned::error& e) { ERR_SERVER << e.message << " while banning" << std::endl; return e.message; } @@ -528,7 +528,7 @@ static lg::log_domain log_server("server"); ban_set::iterator ban; try { ban = bans_.find(banned::create_dummy(ip)); - } catch (banned::error& e) { + } catch (const banned::error& e) { ERR_SERVER << e.message << std::endl; os << e.message; return; @@ -597,7 +597,7 @@ static lg::log_domain log_server("server"); ip_mask pair; try { pair = parse_ip(mask); - } catch (banned::error& e) { + } catch (const banned::error& e) { out << "parse error: " << e.message; return; } @@ -626,7 +626,7 @@ static lg::log_domain log_server("server"); ip_mask pair; try { pair = parse_ip(mask); - } catch (banned::error& e) { + } catch (const banned::error& e) { out << "parse error: " << e.message; return; } @@ -664,7 +664,7 @@ static lg::log_domain log_server("server"); ip_mask pair; try { pair = parse_ip(ip); - } catch (banned::error&) { + } catch (const banned::error&) { return ""; } ban_set::const_iterator ban = std::find_if(bans_.begin(), bans_.end(), [pair](const banned_ptr& p) { return p->match_ip(pair); }); diff --git a/src/server/forum_user_handler.cpp b/src/server/forum_user_handler.cpp index 10f33b203c55..bca84b780fc2 100644 --- a/src/server/forum_user_handler.cpp +++ b/src/server/forum_user_handler.cpp @@ -70,7 +70,7 @@ bool fuh::login(const std::string& name, const std::string& password, const std: try { hash = get_hash(name); - } catch (error& e) { + } catch (const error& e) { ERR_UH << "Could not retrieve hash for user '" << name << "' :" << e.message << std::endl; return false; } @@ -102,7 +102,7 @@ std::string fuh::extract_salt(const std::string& name) { try { hash = get_hash(name); - } catch (error& e) { + } catch (const rror& e) { ERR_UH << "Could not retrieve hash for user '" << name << "' :" << e.message << std::endl; return ""; } @@ -113,7 +113,7 @@ std::string fuh::extract_salt(const std::string& name) { if(utils::bcrypt::is_valid_prefix(hash)) { try { return utils::bcrypt::from_hash_string(hash).get_salt(); - } catch(utils::hash_error& err) { + } catch(const utils::hash_error& err) { ERR_UH << "Error getting salt from hash of user '" << name << "': " << err.what() << std::endl; return ""; } @@ -131,7 +131,7 @@ bool fuh::user_exists(const std::string& name) { // Make a test query for this username try { return prepared_statement("SELECT 1 FROM `" + db_users_table_ + "` WHERE UPPER(username)=UPPER(?)", name); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not execute test query for user '" << name << "' :" << e.message << std::endl; // If the database is down just let all usernames log in return false; @@ -142,7 +142,7 @@ bool fuh::user_is_active(const std::string& name) { try { int user_type = get_detail_for_user(name, "user_type"); return user_type != USER_INACTIVE && user_type != USER_IGNORE; - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not retrieve user type for user '" << name << "' :" << e.message << std::endl; return false; } @@ -154,7 +154,7 @@ bool fuh::user_is_moderator(const std::string& name) { try { return get_writable_detail_for_user(name, "user_is_moderator") == 1; - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not query user_is_moderator for user '" << name << "' :" << e.message << std::endl; // If the database is down mark nobody as a mod return false; @@ -167,7 +167,7 @@ void fuh::set_is_moderator(const std::string& name, const bool& is_moderator) { try { write_detail(name, "user_is_moderator", int(is_moderator)); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not set is_moderator for user '" << name << "' :" << e.message << std::endl; } } @@ -208,7 +208,7 @@ fuh::BAN_TYPE fuh::user_is_banned(const std::string& name, const std::string& ad return BAN_EMAIL; } - } catch(sql_error& e) { + } catch(const sql_error& e) { ERR_UH << "Could not check forum bans on user '" << name << "' :" << e.message << '\n'; } @@ -254,7 +254,7 @@ std::string fuh::get_valid_details() { std::string fuh::get_hash(const std::string& user) { try { return get_detail_for_user(user, "user_password"); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not retrieve password for user '" << user << "' :" << e.message << std::endl; return ""; } @@ -263,7 +263,7 @@ std::string fuh::get_hash(const std::string& user) { std::string fuh::get_mail(const std::string& user) { try { return get_detail_for_user(user, "user_email"); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not retrieve email for user '" << user << "' :" << e.message << std::endl; return ""; } @@ -273,7 +273,7 @@ time_t fuh::get_lastlogin(const std::string& user) { try { int time_int = get_writable_detail_for_user(user, "user_lastvisit"); return time_t(time_int); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not retrieve last visit for user '" << user << "' :" << e.message << std::endl; return time_t(0); } @@ -283,7 +283,7 @@ time_t fuh::get_registrationdate(const std::string& user) { try { int time_int = get_detail_for_user(user, "user_regdate"); return time_t(time_int); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not retrieve registration date for user '" << user << "' :" << e.message << std::endl; return time_t(0); } @@ -293,7 +293,7 @@ void fuh::set_lastlogin(const std::string& user, const time_t& lastlogin) { try { write_detail(user, "user_lastvisit", int(lastlogin)); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not set last visit for user '" << user << "' :" << e.message << std::endl; } } @@ -303,7 +303,7 @@ inline T fuh::prepared_statement(const std::string& sql, Args&&... args) { try { return ::prepared_statement(conn, sql, std::forward(args)...); - } catch (sql_error& e) { + } catch (const sql_error& e) { WRN_UH << "caught sql error: " << e.message << std::endl; WRN_UH << "trying to reconnect and retry..." << std::endl; //Try to reconnect and execute query again @@ -339,7 +339,7 @@ void fuh::write_detail(const std::string& name, const std::string& detail, T&& v prepared_statement("INSERT INTO `" + db_extra_table_ + "` VALUES(?,?,'0')", name, std::forward(value)); } prepared_statement("UPDATE `" + db_extra_table_ + "` SET " + detail + "=? WHERE UPPER(username)=UPPER(?)", std::forward(value), name); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not set detail for user '" << name << "': " << e.message << std::endl; } } @@ -349,7 +349,7 @@ bool fuh::extra_row_exists(const std::string& name) { // Make a test query for this username try { return prepared_statement("SELECT 1 FROM `" + db_extra_table_ + "` WHERE UPPER(username)=UPPER(?)", name); - } catch (sql_error& e) { + } catch (const sql_error& e) { ERR_UH << "Could not execute test query for user '" << name << "' :" << e.message << std::endl; return false; } diff --git a/src/server/game.cpp b/src/server/game.cpp index 556b3244d09e..d1b74fafb9c6 100644 --- a/src/server/game.cpp +++ b/src/server/game.cpp @@ -1768,7 +1768,7 @@ void game::send_history(const socket_ptr& socket) const history_.clear(); history_.push_back(doc); - } catch(simple_wml::error& e) { + } catch(const simple_wml::error& e) { WRN_CONFIG << __func__ << ": simple_wml error: " << e.message << std::endl; } } @@ -1853,7 +1853,7 @@ void game::save_replay() if(!os->good()) { ERR_GAME << "Could not save replay! (" << filename << ")" << std::endl; } - } catch(simple_wml::error& e) { + } catch(const simple_wml::error& e) { WRN_CONFIG << __func__ << ": simple_wml error: " << e.message << std::endl; } } diff --git a/src/server/server.cpp b/src/server/server.cpp index c587260cfe25..9177fafdab12 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -376,7 +376,7 @@ config server::read_config() const { read(configuration, *stream); LOG_SERVER << "Server configuration from file: '" << config_file_ << "' read.\n"; - } catch(config::error& e) { + } catch(const config::error& e) { ERR_CONFIG << "ERROR: Could not read configuration file: '" << config_file_ << "': '" << e.message << "'.\n"; } @@ -1080,7 +1080,7 @@ void server::handle_nickserv(socket_ptr socket, simple_wml::node& nickserv) "user", player_connections_.find(socket)->info().config_address(), diff); send_to_lobby(diff); - } catch (user_handler::error& e) { + } catch (const user_handler::error& e) { send_server_message(socket, "There was an error registering your username. The error message was: " + e.message); } @@ -1101,7 +1101,7 @@ void server::handle_nickserv(socket_ptr socket, simple_wml::node& nickserv) send_server_message(socket, "Your details have been updated."); - } catch (user_handler::error& e) { + } catch (const user_handler::error& e) { send_server_message(socket, "There was an error updating your details. The error message was: " + e.message); } @@ -1121,7 +1121,7 @@ void server::handle_nickserv(socket_ptr socket, simple_wml::node& nickserv) try { std::string res = user_handler_->user_info((*nickserv.child("info"))["name"].to_string()); send_server_message(socket, res); - } catch (user_handler::error& e) { + } catch (const user_handler::error& e) { send_server_message(socket, "There was an error looking up the details of the user '" + (*nickserv.child("info"))["name"].to_string() + "'. " +" The error message was: " + e.message); @@ -1156,7 +1156,7 @@ void server::handle_nickserv(socket_ptr socket, simple_wml::node& nickserv) make_change_diff(games_and_users_list_.root(), nullptr, "user", player_connections_.find(socket)->info().config_address(), diff); send_to_lobby(diff); - } catch (user_handler::error& e) { + } catch (const user_handler::error& e) { send_server_message(socket, "There was an error dropping your username. The error message was: " + e.message); } @@ -2103,7 +2103,7 @@ std::string server::process_command(std::string query, std::string issuer_name) const cmd_handler &handler = handler_itor->second; try { handler(issuer_name, query, parameters, &out); - } catch (std::bad_function_call & ex) { + } catch (const std::bad_function_call & ex) { ERR_SERVER << "While handling a command '" << command << "', caught a std::bad_function_call exception.\n"; ERR_SERVER << ex.what() << std::endl; out << "An internal server error occurred (std::bad_function_call) while executing '" << command << "'\n"; @@ -2112,7 +2112,7 @@ std::string server::process_command(std::string query, std::string issuer_name) return out.str(); - } catch ( utf8::invalid_utf8_exception & e ) { + } catch (const utf8::invalid_utf8_exception & e ) { std::string msg = "While handling a command, caught an invalid utf8 exception: "; msg += e.what(); ERR_SERVER << msg << std::endl; @@ -2412,7 +2412,7 @@ void server::bans_handler(const std::string& /*issuer_name*/, const std::string& ban_manager_.list_bans(*out, parameters); } - } catch ( utf8::invalid_utf8_exception & e ) { + } catch (const utf8::invalid_utf8_exception & e ) { ERR_SERVER << "While handling bans, caught an invalid utf8 exception: " << e.what() << std::endl; } } @@ -2759,7 +2759,7 @@ void server::dul_handler(const std::string& /*issuer_name*/, const std::string& *out << "Unregistered login is now " << (deny_unregistered_login_ ? "disallowed" : "allowed") << "."; } - } catch ( utf8::invalid_utf8_exception & e ) { + } catch (const utf8::invalid_utf8_exception & e ) { ERR_SERVER << "While handling dul (deny unregistered logins), caught an invalid utf8 exception: " << e.what() << std::endl; } } @@ -2919,7 +2919,7 @@ int main(int argc, char** argv) { try { wesnothd::server(port, keep_alive, config_file, min_threads, max_threads).run(); - } catch(std::exception& e) { + } catch(const std::exception& e) { ERR_SERVER << "terminated by C++ exception: " << e.what() << std::endl; return 1; } diff --git a/src/server/simple_wml.cpp b/src/server/simple_wml.cpp index 2dcdcf4455d0..fe5667040fa8 100644 --- a/src/server/simple_wml.cpp +++ b/src/server/simple_wml.cpp @@ -91,7 +91,7 @@ char* uncompress_buffer(const string_span& input, string_span* span) *span = string_span(small_out, pos); state = 8; return small_out; - } catch (std::bad_alloc& e) { + } catch (const std::bad_alloc& e) { ERR_SWML << "ERROR: bad_alloc caught in uncompress_buffer() state " << state << " alloc bytes " << nalloc << " with input: '" << input << "' " << e.what() << std::endl; @@ -144,7 +144,7 @@ char* compress_buffer(const char* input, string_span* span, bool bzip2) assert(*small_out == (bzip2 ? 'B' : 31)); state = 9; return small_out; - } catch (std::bad_alloc& e) { + } catch (const std::bad_alloc& e) { ERR_SWML << "ERROR: bad_alloc caught in compress_buffer() state " << state << " alloc bytes " << nalloc << " with input: '" << input << "' " << e.what() << std::endl; @@ -1047,7 +1047,7 @@ const char* document::output() char* buf; try { buf = new char[buf_size]; - } catch (std::bad_alloc& e) { + } catch (const std::bad_alloc& e) { ERR_SWML << "ERROR: Trying to allocate " << buf_size << " bytes. " << e.what() << std::endl; throw error("Bad allocation request in output()."); diff --git a/src/side_filter.cpp b/src/side_filter.cpp index 1f54a7625053..6d2b529fd683 100644 --- a/src/side_filter.cpp +++ b/src/side_filter.cpp @@ -236,7 +236,7 @@ bool side_filter::match_internal(const team &t) const return false; } return true; - } catch(wfl::formula_error& e) { + } catch(const wfl::formula_error& e) { lg::wml_error() << "Formula error in side filter: " << e.type << " at " << e.filename << ':' << e.line << ")\n"; // Formulae with syntax errors match nothing return false; diff --git a/src/statistics.cpp b/src/statistics.cpp index 8ce247056292..25f20228d079 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -150,7 +150,7 @@ static stats::str_int_map read_str_int_map(const config& cfg) for(const std::string& val : utils::split(i.second)) { m[val] = std::stoi(i.first); } - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_NG << "Invalid statistics entry; skipping\n"; } } diff --git a/src/synced_commands.cpp b/src/synced_commands.cpp index de17000a0880..c4aa81675c12 100644 --- a/src/synced_commands.cpp +++ b/src/synced_commands.cpp @@ -261,7 +261,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(move, child, use_undo, show, error_handler) try { read_locations(child,steps); - } catch (std::invalid_argument&) { + } catch (const std::invalid_argument&) { WRN_REPLAY << "Warning: Path data contained something which could not be parsed to a sequence of locations:" << "\n config = " << child.debug() << std::endl; return false; } @@ -493,7 +493,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(debug_unit, child, use_undo, /*show*/, /*error_ resources::gameboard->units().erase(loc); resources::whiteboard->on_kill_unit(); resources::gameboard->units().insert(new_u); - } catch(unit_type::error& e) { + } catch(const unit_type::error& e) { ERR_REPLAY << e.what() << std::endl; // TODO: more appropriate error message log return false; } diff --git a/src/terrain/builder.cpp b/src/terrain/builder.cpp index dc3b038cbdef..58aa1aa23a3a 100644 --- a/src/terrain/builder.cpp +++ b/src/terrain/builder.cpp @@ -466,7 +466,7 @@ bool terrain_builder::load_images(building_rule& rule) if(items.size() > 1) { try { time = std::stoi(items.back()); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_NG << "Invalid 'time' value in terrain image builder: " << items.back() << "\n"; } } @@ -694,7 +694,7 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi try { basex = std::stoi(base[0]); basey = std::stoi(base[1]); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_NG << "Invalid 'base' value in terrain image builder: " << base[0] << ", " << base[1] << "\n"; } } @@ -707,7 +707,7 @@ void terrain_builder::add_images_from_config(rule_imagelist& images, const confi try { center_x = std::stoi(center[0]); center_y = std::stoi(center[1]); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { ERR_NG << "Invalid 'center' value in terrain image builder: " << center[0] << ", " << center[1] << "\n"; } diff --git a/src/terrain/filter.cpp b/src/terrain/filter.cpp index 75b6f905dd75..d35f6e308e65 100644 --- a/src/terrain/filter.cpp +++ b/src/terrain/filter.cpp @@ -340,7 +340,7 @@ bool terrain_filter::match_internal(const map_location& loc, const unit* ref_uni return false; } return true; - } catch(wfl::formula_error& e) { + } catch(const wfl::formula_error& e) { lg::wml_error() << "Formula error in location filter: " << e.type << " at " << e.filename << ':' << e.line << ")\n"; // Formulae with syntax errors match nothing return false; diff --git a/src/terrain/translation.cpp b/src/terrain/translation.cpp index 769359f99678..72ff73119628 100644 --- a/src/terrain/translation.cpp +++ b/src/terrain/translation.cpp @@ -751,7 +751,7 @@ static terrain_code string_to_number_(std::string str, std::string& start_positi if(offset < end) { try { start_position = str.substr(begin, offset - begin); - } catch(bad_lexical_cast&) { + } catch(const bad_lexical_cast&) { return VOID_TERRAIN; } begin = offset + 1; diff --git a/src/tests/gui/test_gui2.cpp b/src/tests/gui/test_gui2.cpp index fa31d0ef8524..5f622eff1da5 100644 --- a/src/tests/gui/test_gui2.cpp +++ b/src/tests/gui/test_gui2.cpp @@ -201,15 +201,15 @@ namespace { std::string exception; try { dlg->show(1); - } catch(gui2::layout_exception_width_modified&) { + } catch(const gui2::layout_exception_width_modified&) { exception = "gui2::layout_exception_width_modified"; - } catch(gui2::layout_exception_width_resize_failed&) { + } catch(const gui2::layout_exception_width_resize_failed&) { exception = "gui2::layout_exception_width_resize_failed"; - } catch(gui2::layout_exception_height_resize_failed&) { + } catch(const gui2::layout_exception_height_resize_failed&) { exception = "gui2::layout_exception_height_resize_failed"; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { exception = e.dev_message; - } catch(std::exception& e) { + } catch(const std::exception& e) { exception = e.what(); } catch(...) { exception = "unknown"; @@ -243,15 +243,15 @@ namespace { gui2::window* window = unit_test_window((*dlg.get())); BOOST_REQUIRE_NE(window, static_cast(nullptr)); window->draw(); - } catch(gui2::layout_exception_width_modified&) { + } catch(const gui2::layout_exception_width_modified&) { exception = "gui2::layout_exception_width_modified"; - } catch(gui2::layout_exception_width_resize_failed&) { + } catch(const gui2::layout_exception_width_resize_failed&) { exception = "gui2::layout_exception_width_resize_failed"; - } catch(gui2::layout_exception_height_resize_failed&) { + } catch(const gui2::layout_exception_height_resize_failed&) { exception = "gui2::layout_exception_height_resize_failed"; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { exception = e.dev_message; - } catch(std::exception& e) { + } catch(const std::exception& e) { exception = e.what(); } catch(...) { exception = "unknown"; @@ -287,15 +287,15 @@ namespace { , "Test message for a tooltip." , point(0, 0) , {0,0,0,0}); - } catch(gui2::layout_exception_width_modified&) { + } catch(const gui2::layout_exception_width_modified&) { exception = "gui2::layout_exception_width_modified"; - } catch(gui2::layout_exception_width_resize_failed&) { + } catch(const gui2::layout_exception_width_resize_failed&) { exception = "gui2::layout_exception_width_resize_failed"; - } catch(gui2::layout_exception_height_resize_failed&) { + } catch(const gui2::layout_exception_height_resize_failed&) { exception = "gui2::layout_exception_height_resize_failed"; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { exception = e.dev_message; - } catch(std::exception& e) { + } catch(const std::exception& e) { exception = e.what(); } catch(...) { exception = "unknown"; @@ -565,7 +565,7 @@ BOOST_AUTO_TEST_CASE(test_make_test_fake) try { message dlg("title", "message", true, false, false); dlg.show(1); - } catch(wml_exception& e) { + } catch(const wml_exception& e) { BOOST_CHECK(e.user_message == _("Failed to show a dialog, " "which doesn't fit on the screen.")); return; diff --git a/src/tests/test_make_enum.cpp b/src/tests/test_make_enum.cpp index c26dc7c0ae2c..fa3bf414799a 100644 --- a/src/tests/test_make_enum.cpp +++ b/src/tests/test_make_enum.cpp @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE ( test_make_enum_namespace ) try { e = lexical_cast ("name3"); //returns con3 - } catch (bad_lexical_cast & /*e*/) { + } catch (const bad_lexical_cast & /*e*/) { //std::cerr << "enum lexical cast didn't work!" << std::endl; threw_exception_when_it_wasnt_supposed_to = true; } @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE ( test_make_enum_namespace ) try { e = lexical_cast ("name4"); //throw bad_lexical_cast - } catch (bad_lexical_cast & /*e*/) { + } catch (const bad_lexical_cast & /*e*/) { //std::cerr << "enum lexical cast worked!" << std::endl; threw_exception_when_it_was_supposed_to = true; } @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE ( test_make_enum_class ) try { e = lexical_cast ("name3"); //returns val3 - } catch (bad_lexical_cast & /*e*/) { + } catch(const bad_lexical_cast & /*e*/) { //std::cerr << "enum lexical cast didn't work!" << std::endl; threw_exception_when_it_wasnt_supposed_to = true; } @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE ( test_make_enum_class ) try { e = lexical_cast ("name4"); //throw bad_lexical_cast - } catch (bad_lexical_cast & /*e*/) { + } catch (const bad_lexical_cast & /*e*/) { //std::cerr << "enum lexical cast worked!" << std::endl; threw_exception_when_it_was_supposed_to = true; } diff --git a/src/tod_manager.cpp b/src/tod_manager.cpp index 3efcfe9a76eb..2b0bcf2a19f1 100644 --- a/src/tod_manager.cpp +++ b/src/tod_manager.cpp @@ -90,7 +90,7 @@ void tod_manager::resolve_random(randomness::rng& r) return std::stoi(str); }); } - catch (std::invalid_argument&) + catch (const std::invalid_argument&) { // This happens if the random_start_time string is a boolean. // Simply ignore the exception. diff --git a/src/units/abilities.cpp b/src/units/abilities.cpp index 71f3234c3ed3..69a97d35c7ab 100644 --- a/src/units/abilities.cpp +++ b/src/units/abilities.cpp @@ -467,7 +467,7 @@ T get_single_ability_value(const config::attribute_value& v, T def, const map_lo callable.add("other", wfl::variant(std::make_shared(*u_itor))); } return formula_handler(wfl::formula(s, new wfl::gamestate_function_symbol_table), callable); - } catch(wfl::formula_error& e) { + } catch(const wfl::formula_error& e) { lg::wml_error() << "Formula error in ability or weapon special: " << e.type << " at " << e.filename << ':' << e.line << ")\n"; return def; } diff --git a/src/units/attack_type.cpp b/src/units/attack_type.cpp index 47fa51218fe7..c0e2f959e63e 100644 --- a/src/units/attack_type.cpp +++ b/src/units/attack_type.cpp @@ -144,7 +144,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil if(!form.evaluate(callable).as_bool()) { return false; } - } catch(wfl::formula_error& e) { + } catch(const wfl::formula_error& e) { lg::wml_error() << "Formula error in weapon filter: " << e.type << " at " << e.filename << ':' << e.line << ")\n"; // Formulae with syntax errors match nothing return false; diff --git a/src/units/filter.cpp b/src/units/filter.cpp index dbd269e6c028..bcf25898b25d 100644 --- a/src/units/filter.cpp +++ b/src/units/filter.cpp @@ -627,7 +627,7 @@ void unit_filter_compound::fill(vconfig cfg) return false; } return true; - } catch(wfl::formula_error& e) { + } catch(const wfl::formula_error& e) { lg::wml_error() << "Formula error in unit filter: " << e.type << " at " << e.filename << ':' << e.line << ")\n"; // Formulae with syntax errors match nothing return false; diff --git a/src/units/frame_private.hpp b/src/units/frame_private.hpp index 7668279410dd..177f3a3d25a7 100644 --- a/src/units/frame_private.hpp +++ b/src/units/frame_private.hpp @@ -92,7 +92,7 @@ class progressive_pair : public progressive_base> try { time = (colon_split.size() > 1) ? std::stoi(colon_split[1]) : time_chunk; - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { //ERR_NG << "Invalid time in unit animation: " << colon_split[1] << "\n"; } @@ -102,7 +102,7 @@ class progressive_pair : public progressive_base> T range1 = (range.size() > 1) ? lexical_cast(range[1]) : range0; base_data.push_back({{range0, range1}, time}); - } catch(bad_lexical_cast&) {} + } catch(const bad_lexical_cast&) {} } } @@ -169,7 +169,7 @@ class progressive_single : public progressive_base if(second_pass.size() > 1) { try { total_specified_time += std::stoi(second_pass[1]); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { //ERR_NG << "Invalid time in unit animation: " << second_pass[1] << "\n"; } } @@ -183,7 +183,7 @@ class progressive_single : public progressive_base if(second_pass.size() > 1) { try { base_data.push_back({std::move(second_pass[0]), std::stoi(second_pass[1])}); - } catch(std::invalid_argument&) { + } catch(const std::invalid_argument&) { //ERR_NG << "Invalid time in unit animation: " << second_pass[1] << "\n"; } } else { diff --git a/src/units/unit.cpp b/src/units/unit.cpp index 0d2cf2b8b7b0..cfab16ce9a52 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -727,7 +727,7 @@ unit::~unit() if(itor != units_with_cache.end()) { units_with_cache.erase(itor); } - } catch(std::exception & e) { + } catch(const std::exception & e) { ERR_UT << "Caught exception when destroying unit: " << e.what() << std::endl; } catch(...) {} } diff --git a/src/variable.cpp b/src/variable.cpp index 3c517b884c12..95bdd0463012 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -169,7 +169,7 @@ config vconfig::get_parsed_config() const { res.add_child(name); } - catch(recursion_error &err) { + catch(const recursion_error &err) { vconfig_recursion.erase(vname); WRN_NG << err.message << std::endl; if(vconfig_recursion.empty()) { diff --git a/src/wesnoth.cpp b/src/wesnoth.cpp index f631dac0a500..63ae4deda59e 100644 --- a/src/wesnoth.cpp +++ b/src/wesnoth.cpp @@ -173,7 +173,7 @@ static void encode(const std::string& input_file, const std::string& output_file ifile.close(); safe_exit(remove(input_file.c_str())); - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { std::cerr << "IO error: " << e.what() << "\n"; } } @@ -193,7 +193,7 @@ static void decode(const std::string& input_file, const std::string& output_file ifile.close(); safe_exit(remove(input_file.c_str())); - } catch(filesystem::io_exception& e) { + } catch(const filesystem::io_exception& e) { std::cerr << "IO error: " << e.what() << "\n"; } } @@ -236,7 +236,7 @@ static void handle_preprocess_command(const commandline_options& cmdline_opts) try { filesystem::scoped_istream stream = filesystem::istream_file(file); read(cfg, *stream); - } catch(config::error& e) { + } catch(const config::error& e) { std::cerr << "Caught a config error while parsing file '" << file << "':\n" << e.message << std::endl; } @@ -1142,40 +1142,40 @@ int main(int argc, char** argv) const int res = do_gameloop(args); safe_exit(res); - } catch(boost::program_options::error& e) { + } catch(const boost::program_options::error& e) { std::cerr << "Error in command line: " << e.what() << '\n'; error_exit(1); - } catch(CVideo::error& e) { + } catch(const CVideo::error& e) { std::cerr << "Could not initialize video.\n\n" << e.what() << "\n\nExiting.\n"; error_exit(1); - } catch(font::error& e) { + } catch(const font::error& e) { std::cerr << "Could not initialize fonts.\n\n" << e.what() << "\n\nExiting.\n"; error_exit(1); - } catch(config::error& e) { + } catch(const config::error& e) { std::cerr << e.message << "\n"; error_exit(1); - } catch(gui::button::error&) { + } catch(const gui::button::error&) { std::cerr << "Could not create button: Image could not be found\n"; error_exit(1); - } catch(CVideo::quit&) { + } catch(const CVideo::quit&) { // just means the game should quit - } catch(return_to_play_side_exception&) { + } catch(const return_to_play_side_exception&) { std::cerr << "caught return_to_play_side_exception, please report this bug (quitting)\n"; - } catch(quit_game_exception&) { + } catch(const quit_game_exception&) { std::cerr << "caught quit_game_exception (quitting)\n"; - } catch(wml_exception& e) { + } catch(const wml_exception& e) { std::cerr << "WML exception:\nUser message: " << e.user_message << "\nDev message: " << e.dev_message << '\n'; error_exit(1); - } catch(wfl::formula_error& e) { + } catch(const wfl::formula_error& e) { std::cerr << e.what() << "\n\nGame will be aborted.\n"; error_exit(1); } catch(const sdl::exception& e) { std::cerr << e.what(); error_exit(1); - } catch(game::error&) { + } catch(const game::error&) { // A message has already been displayed. error_exit(1); - } catch(std::bad_alloc&) { + } catch(const std::bad_alloc&) { std::cerr << "Ran out of memory. Aborted.\n"; error_exit(ENOMEM); #if !defined(NO_CATCH_AT_GAME_END) @@ -1183,7 +1183,7 @@ int main(int argc, char** argv) // Try to catch unexpected exceptions. std::cerr << "Caught general '" << typeid(e).name() << "' exception:\n" << e.what() << std::endl; error_exit(1); - } catch(std::string& e) { + } catch(const std::string& e) { std::cerr << "Caught a string thrown as an exception:\n" << e << std::endl; error_exit(1); } catch(const char* e) { diff --git a/src/whiteboard/move.cpp b/src/whiteboard/move.cpp index 8298ab72cb48..65f3d89dd328 100644 --- a/src/whiteboard/move.cpp +++ b/src/whiteboard/move.cpp @@ -231,7 +231,7 @@ void move::execute(bool& success, bool& complete) try { events::mouse_handler& mouse_handler = resources::controller->get_mouse_handler_base(); num_steps = mouse_handler.move_unit_along_route(steps, interrupted); - } catch (return_to_play_side_exception&) { + } catch (const return_to_play_side_exception&) { set_arrow_brightness(ARROW_BRIGHTNESS_STANDARD); throw; // we rely on the caller to delete this action } diff --git a/src/whiteboard/side_actions.cpp b/src/whiteboard/side_actions.cpp index cc9176972c5f..63cec8950b6f 100644 --- a/src/whiteboard/side_actions.cpp +++ b/src/whiteboard/side_actions.cpp @@ -348,7 +348,7 @@ bool side_actions::execute(side_actions::iterator position) bool action_complete; try { action->execute(action_successful, action_complete); - } catch (return_to_play_side_exception&) { + } catch (const return_to_play_side_exception&) { synced_erase(position); LOG_WB << "End turn exception caught during execution, deleting action. " << *this << "\n"; //validate actions at next map rebuild