Skip to content

Commit

Permalink
Catch std::exception by reference (#20385)
Browse files Browse the repository at this point in the history
  • Loading branch information
NN--- committed Sep 11, 2022
1 parent 675d79a commit 922d21f
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion installer/PowerToysSetupCustomActions/CustomAction.cpp
Expand Up @@ -982,7 +982,7 @@ UINT __stdcall UnRegisterContextMenuPackagesCA(MSIHANDLE hInstall)
}
}
}
catch (std::exception e)
catch (std::exception& e)
{
std::string errorMessage{ "Exception thrown while trying to unregister sparse packages: " };
errorMessage += e.what();
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/package.h
Expand Up @@ -102,7 +102,7 @@ namespace package {

return true;
}
catch (std::exception e)
catch (std::exception& e)
{
Logger::error("Exception thrown while trying to register package: {}", e.what());

Expand Down
Expand Up @@ -128,7 +128,7 @@ class MeasureTool : public PowertoyModuleIface

parse_hotkey(settings);
}
catch (std::exception ex)
catch (std::exception&)
{
Logger::warn(L"An exception occurred while loading the settings file");
// Error while loading from the settings file. Let default values stay as they are.
Expand Down Expand Up @@ -208,7 +208,7 @@ class MeasureTool : public PowertoyModuleIface
// Otherwise call a custom function to process the settings before saving them to disk:
// save_settings();
}
catch (std::exception ex)
catch (std::exception&)
{
// Improper JSON.
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/PowerOCR/PowerOCRModuleInterface/dllmain.cpp
Expand Up @@ -144,7 +144,7 @@ class PowerOCR : public PowertoyModuleIface

parse_hotkey(settings);
}
catch (std::exception ex)
catch (std::exception&)
{
Logger::warn(L"An exception occurred while loading the settings file");
// Error while loading from the settings file. Let default values stay as they are.
Expand Down Expand Up @@ -220,7 +220,7 @@ class PowerOCR : public PowertoyModuleIface
// Otherwise call a custom function to process the settings before saving them to disk:
// save_settings();
}
catch (std::exception ex)
catch (std::exception&)
{
// Improper JSON.
}
Expand Down
Expand Up @@ -66,7 +66,7 @@ class ShortcutGuideModule : public PowertoyModuleIface

ParseSettings(values);
}
catch (std::exception ex)
catch (std::exception& ex)
{
Logger::error("Failed to parse settings. {}", ex.what());
}
Expand Down Expand Up @@ -261,7 +261,7 @@ class ShortcutGuideModule : public PowertoyModuleIface

ParseSettings(settings);
}
catch (std::exception ex)
catch (std::exception& ex)
{
Logger::error("Failed to init settings. {}", ex.what());
}
Expand Down
Expand Up @@ -94,7 +94,7 @@ class AlwaysOnTopModuleInterface : public PowertoyModuleIface
// Otherwise call a custom function to process the settings before saving them to disk:
// save_settings();
}
catch (std::exception ex)
catch (std::exception&)
{
// Improper JSON.
}
Expand Down Expand Up @@ -273,7 +273,7 @@ class AlwaysOnTopModuleInterface : public PowertoyModuleIface

parse_hotkey(settings);
}
catch (std::exception ex)
catch (std::exception&)
{
Logger::warn(L"An exception occurred while loading the settings file");
// Error while loading from the settings file. Let default values stay as they are.
Expand Down
4 changes: 2 additions & 2 deletions src/modules/colorPicker/ColorPicker/dllmain.cpp
Expand Up @@ -144,7 +144,7 @@ class ColorPicker : public PowertoyModuleIface

parse_hotkey(settings);
}
catch (std::exception ex)
catch (std::exception&)
{
Logger::warn(L"An exception occurred while loading the settings file");
// Error while loading from the settings file. Let default values stay as they are.
Expand Down Expand Up @@ -221,7 +221,7 @@ class ColorPicker : public PowertoyModuleIface
// Otherwise call a custom function to process the settings before saving them to disk:
// save_settings();
}
catch (std::exception ex)
catch (std::exception&)
{
// Improper JSON.
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/launcher/Microsoft.Launcher/dllmain.cpp
Expand Up @@ -176,7 +176,7 @@ class Microsoft_Launcher : public PowertoyModuleIface
PowerToysSettings::CustomActionObject action_object =
PowerToysSettings::CustomActionObject::from_json_string(action);
}
catch (std::exception ex)
catch (std::exception&)
{
// Improper JSON.
}
Expand All @@ -198,7 +198,7 @@ class Microsoft_Launcher : public PowertoyModuleIface
// Otherwise call a custom function to process the settings before saving them to disk:
// save_settings();
}
catch (std::exception ex)
catch (std::exception&)
{
// Improper JSON.
}
Expand Down Expand Up @@ -366,7 +366,7 @@ void Microsoft_Launcher::init_settings()

parse_hotkey(settings);
}
catch (std::exception ex)
catch (std::exception&)
{
// Error while loading from the settings file. Let default values stay as they are.
}
Expand Down
Expand Up @@ -187,7 +187,7 @@ namespace winrt::PowerRenameUI::implementation
SetHandlers();
ReadSettings();
}
catch (std::exception e)
catch (std::exception& e)
{
Logger::error("Exception thrown during explorer items population: {}", std::string{ e.what() });
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/powerrename/dll/dllmain.cpp
Expand Up @@ -286,7 +286,7 @@ class PowerRenameModule : public PowertoyModuleIface

Trace::SettingsChanged();
}
catch (std::exception e)
catch (std::exception& e)
{
Logger::error("Configuration parsing failed: {}", std::string{ e.what() });
}
Expand Down
2 changes: 1 addition & 1 deletion src/runner/centralized_hotkeys.cpp
Expand Up @@ -103,7 +103,7 @@ namespace CentralizedHotkeys
{
actions[shortcut].begin()->action(shortcut.modifiersMask, shortcut.vkCode);
}
catch(std::exception ex)
catch(std::exception& ex)
{
Logger::error("Failed to execute hotkey's action. {}", ex.what());
}
Expand Down
2 changes: 1 addition & 1 deletion tools/project_template/ModuleTemplate/dllmain.cpp
Expand Up @@ -286,7 +286,7 @@ void $safeprojectname$::init_settings()
// // Save the PowerToyValues JSON to the power toy settings file.
// values.save_to_settings_file();
// }
// catch (std::exception ex) {
// catch (std::exception& ex) {
// // Couldn't save the settings.
// }
//}
Expand Down
10 changes: 5 additions & 5 deletions tools/project_template/README.md
Expand Up @@ -147,7 +147,7 @@ Here's an example settings implementation:
// Otherwise call a custom function to process the settings before saving them to disk:
// save_settings();
}
catch (std::exception ex) {
catch (std::exception& ex) {
// Improper JSON.
}
}
Expand Down Expand Up @@ -325,7 +325,7 @@ When the custom action button is pressed, the PowerToy's `call_custom_action()`
MessageBox(NULL, msg.c_str(), L"Custom action call.", MB_OK | MB_TOPMOST);
}
}
catch (std::exception ex) {
catch (std::exception& ex) {
// Improper JSON.
}
}
Expand Down Expand Up @@ -371,7 +371,7 @@ void ExamplePowertoy::init_settings() {
g_settings.test_color_prop = settings.get_string_value(L"test_color_picker");
}
}
catch (std::exception ex) {
catch (std::exception& ex) {
// Error while loading from the settings file. Let default values stay as they are.
}
}
Expand All @@ -392,7 +392,7 @@ virtual void set_config(const wchar_t* config) override {
...
values.save_to_settings_file();
}
catch (std::exception ex) {
catch (std::exception& ex) {
// Improper JSON.
}
}
Expand Down Expand Up @@ -434,7 +434,7 @@ void ExamplePowertoy::save_settings() {
// Save the PowerToyValues JSON to the power toy settings file.
values.save_to_settings_file();
}
catch (std::exception ex) {
catch (std::exception& ex) {
// Couldn't save the settings.
}
}
Expand Down

0 comments on commit 922d21f

Please sign in to comment.