From 694415f8af59af04fc72576554f3c93ec46c1aa9 Mon Sep 17 00:00:00 2001 From: Rajendra Singh Date: Tue, 8 Jan 2019 22:42:42 +0530 Subject: [PATCH] Make exception error more clear Close #5212 --- .../MISC/PluginsManager/PluginsManager.cpp | 10 ++-- .../src/MISC/PluginsManager/PluginsManager.h | 10 ++++ .../OpenSaveFileDialog/FileDialog.cpp | 48 +++++++++++++------ .../VerticalFileSwitcherListView.h | 4 +- .../src/WinControls/WindowsDlg/WinMgr.h | 2 +- 5 files changed, 52 insertions(+), 22 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index 7d44fc6b0..b30430cdb 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -259,7 +259,7 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath) } catch (std::exception& e) { - ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); + pluginExceptionAlert(pluginFileName, e); return -1; } catch (generic_string s) @@ -537,7 +537,7 @@ void PluginsManager::runPluginCommand(const TCHAR *pluginName, int commandID) } catch (std::exception& e) { - ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); + pluginExceptionAlert(_pluginsCommands[i]._pluginName.c_str(), e); } catch (...) { @@ -567,7 +567,7 @@ void PluginsManager::notify(size_t indexPluginInfo, const SCNotification *notifi } catch (std::exception& e) { - ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); + pluginExceptionAlert(_pluginInfos[indexPluginInfo]->_moduleName.c_str(), e); } catch (...) { @@ -605,7 +605,7 @@ void PluginsManager::relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam } catch (std::exception& e) { - ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); + pluginExceptionAlert(_pluginInfos[i]->_moduleName.c_str(), e); } catch (...) { @@ -636,7 +636,7 @@ bool PluginsManager::relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lPa } catch (std::exception& e) { - ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); + pluginExceptionAlert(_pluginInfos[i]->_moduleName.c_str(), e); } catch (...) { diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h index 921aa3e4a..b29aae14b 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h @@ -148,6 +148,16 @@ private: ::MessageBox(NULL, msg.c_str(), TEXT("Plugin Crash"), MB_OK|MB_ICONSTOP); } + void pluginExceptionAlert(const TCHAR *pluginName, const std::exception& e) + { + generic_string msg = TEXT("An exception occurred due to plugin: "); + msg += pluginName; + msg += TEXT("\r\n\r\nException reason: "); + msg += s2ws(e.what()); + + ::MessageBox(NULL, msg.c_str(), TEXT("Plugin Exception"), MB_OK); + } + bool isInLoadedDlls(const TCHAR *fn) const { for (size_t i = 0; i < _loadedDlls.size(); ++i) diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp index bdfe873f7..7290be1bd 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp @@ -175,21 +175,31 @@ TCHAR* FileDialog::doOpenSingleFileDlg() } TCHAR *fn = NULL; - try { - fn = ::GetOpenFileName(&_ofn)?_fileName:NULL; - + try + { + fn = ::GetOpenFileName(&_ofn) ? _fileName : NULL; + if (params->getNppGUI()._openSaveDir == dir_last) { ::GetCurrentDirectory(MAX_PATH, dir); params->setWorkingDir(dir); } - } catch(std::exception& e) { - ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); - } catch(...) { + } + catch (std::exception& e) + { + generic_string msg = TEXT("An exception occurred while opening file: "); + msg += _fileName; + msg += TEXT("\r\n\r\nException reason: "); + msg += s2ws(e.what()); + + ::MessageBox(NULL, msg.c_str(), TEXT("File Open Exception"), MB_OK); + } + catch (...) + { ::MessageBox(NULL, TEXT("doOpenSingleFileDlg crashes!!!"), TEXT(""), MB_OK); } - ::SetCurrentDirectory(dir); + ::SetCurrentDirectory(dir); return (fn); } @@ -251,7 +261,7 @@ stringVector * FileDialog::doOpenMultiFilesDlg() } -TCHAR * FileDialog::doSaveDlg() +TCHAR * FileDialog::doSaveDlg() { TCHAR dir[MAX_PATH]; ::GetCurrentDirectory(MAX_PATH, dir); @@ -268,20 +278,30 @@ TCHAR * FileDialog::doSaveDlg() } TCHAR *fn = NULL; - try { - fn = ::GetSaveFileName(&_ofn)?_fileName:NULL; + try + { + fn = ::GetSaveFileName(&_ofn) ? _fileName : NULL; if (params->getNppGUI()._openSaveDir == dir_last) { ::GetCurrentDirectory(MAX_PATH, dir); params->setWorkingDir(dir); } - } catch(std::exception& e) { - ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); - } catch(...) { + } + catch (std::exception& e) + { + generic_string msg = TEXT("An exception occurred while saving file: "); + msg += _fileName; + msg += TEXT("\r\n\r\nException reason: "); + msg += s2ws(e.what()); + + ::MessageBox(NULL, msg.c_str(), TEXT("File Save Exception"), MB_OK); + } + catch (...) + { ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); } - ::SetCurrentDirectory(dir); + ::SetCurrentDirectory(dir); return (fn); } diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h index 916e51e1f..cf30a1a9a 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h @@ -88,8 +88,8 @@ public: }; protected: - HIMAGELIST _hImaLst; - WNDPROC _defaultProc; + HIMAGELIST _hImaLst = nullptr; + WNDPROC _defaultProc = nullptr; LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { diff --git a/PowerEditor/src/WinControls/WindowsDlg/WinMgr.h b/PowerEditor/src/WinControls/WindowsDlg/WinMgr.h index 7e310ed97..6cf6c91ee 100644 --- a/PowerEditor/src/WinControls/WindowsDlg/WinMgr.h +++ b/PowerEditor/src/WinControls/WindowsDlg/WinMgr.h @@ -277,7 +277,7 @@ public: // Theo - Removed Tracing protected: - WINRECT* m_map; // THE window map + WINRECT* m_map = nullptr; // THE window map int CountWindows(); BOOL SendGetSizeInfo(SIZEINFO& szi, HWND hWnd, UINT nID);