Make exception error more clear

Close #5212
This commit is contained in:
Rajendra Singh 2019-01-08 22:42:42 +05:30 committed by Don HO
parent 0f936707a2
commit 694415f8af
5 changed files with 52 additions and 22 deletions

View File

@ -259,7 +259,7 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath)
} }
catch (std::exception& e) catch (std::exception& e)
{ {
::MessageBoxA(NULL, e.what(), "Exception", MB_OK); pluginExceptionAlert(pluginFileName, e);
return -1; return -1;
} }
catch (generic_string s) catch (generic_string s)
@ -537,7 +537,7 @@ void PluginsManager::runPluginCommand(const TCHAR *pluginName, int commandID)
} }
catch (std::exception& e) catch (std::exception& e)
{ {
::MessageBoxA(NULL, e.what(), "Exception", MB_OK); pluginExceptionAlert(_pluginsCommands[i]._pluginName.c_str(), e);
} }
catch (...) catch (...)
{ {
@ -567,7 +567,7 @@ void PluginsManager::notify(size_t indexPluginInfo, const SCNotification *notifi
} }
catch (std::exception& e) catch (std::exception& e)
{ {
::MessageBoxA(NULL, e.what(), "Exception", MB_OK); pluginExceptionAlert(_pluginInfos[indexPluginInfo]->_moduleName.c_str(), e);
} }
catch (...) catch (...)
{ {
@ -605,7 +605,7 @@ void PluginsManager::relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam
} }
catch (std::exception& e) catch (std::exception& e)
{ {
::MessageBoxA(NULL, e.what(), "Exception", MB_OK); pluginExceptionAlert(_pluginInfos[i]->_moduleName.c_str(), e);
} }
catch (...) catch (...)
{ {
@ -636,7 +636,7 @@ bool PluginsManager::relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lPa
} }
catch (std::exception& e) catch (std::exception& e)
{ {
::MessageBoxA(NULL, e.what(), "Exception", MB_OK); pluginExceptionAlert(_pluginInfos[i]->_moduleName.c_str(), e);
} }
catch (...) catch (...)
{ {

View File

@ -148,6 +148,16 @@ private:
::MessageBox(NULL, msg.c_str(), TEXT("Plugin Crash"), MB_OK|MB_ICONSTOP); ::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 bool isInLoadedDlls(const TCHAR *fn) const
{ {
for (size_t i = 0; i < _loadedDlls.size(); ++i) for (size_t i = 0; i < _loadedDlls.size(); ++i)

View File

@ -175,21 +175,31 @@ TCHAR* FileDialog::doOpenSingleFileDlg()
} }
TCHAR *fn = NULL; TCHAR *fn = NULL;
try { try
fn = ::GetOpenFileName(&_ofn)?_fileName:NULL; {
fn = ::GetOpenFileName(&_ofn) ? _fileName : NULL;
if (params->getNppGUI()._openSaveDir == dir_last) if (params->getNppGUI()._openSaveDir == dir_last)
{ {
::GetCurrentDirectory(MAX_PATH, dir); ::GetCurrentDirectory(MAX_PATH, dir);
params->setWorkingDir(dir); params->setWorkingDir(dir);
} }
} catch(std::exception& e) { }
::MessageBoxA(NULL, e.what(), "Exception", MB_OK); catch (std::exception& e)
} catch(...) { {
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); ::MessageBox(NULL, TEXT("doOpenSingleFileDlg crashes!!!"), TEXT(""), MB_OK);
} }
::SetCurrentDirectory(dir); ::SetCurrentDirectory(dir);
return (fn); return (fn);
} }
@ -251,7 +261,7 @@ stringVector * FileDialog::doOpenMultiFilesDlg()
} }
TCHAR * FileDialog::doSaveDlg() TCHAR * FileDialog::doSaveDlg()
{ {
TCHAR dir[MAX_PATH]; TCHAR dir[MAX_PATH];
::GetCurrentDirectory(MAX_PATH, dir); ::GetCurrentDirectory(MAX_PATH, dir);
@ -268,20 +278,30 @@ TCHAR * FileDialog::doSaveDlg()
} }
TCHAR *fn = NULL; TCHAR *fn = NULL;
try { try
fn = ::GetSaveFileName(&_ofn)?_fileName:NULL; {
fn = ::GetSaveFileName(&_ofn) ? _fileName : NULL;
if (params->getNppGUI()._openSaveDir == dir_last) if (params->getNppGUI()._openSaveDir == dir_last)
{ {
::GetCurrentDirectory(MAX_PATH, dir); ::GetCurrentDirectory(MAX_PATH, dir);
params->setWorkingDir(dir); params->setWorkingDir(dir);
} }
} catch(std::exception& e) { }
::MessageBoxA(NULL, e.what(), "Exception", MB_OK); catch (std::exception& e)
} catch(...) { {
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); ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK);
} }
::SetCurrentDirectory(dir); ::SetCurrentDirectory(dir);
return (fn); return (fn);
} }

View File

@ -88,8 +88,8 @@ public:
}; };
protected: protected:
HIMAGELIST _hImaLst; HIMAGELIST _hImaLst = nullptr;
WNDPROC _defaultProc; WNDPROC _defaultProc = nullptr;
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {

View File

@ -277,7 +277,7 @@ public:
// Theo - Removed Tracing // Theo - Removed Tracing
protected: protected:
WINRECT* m_map; // THE window map WINRECT* m_map = nullptr; // THE window map
int CountWindows(); int CountWindows();
BOOL SendGetSizeInfo(SIZEINFO& szi, HWND hWnd, UINT nID); BOOL SendGetSizeInfo(SIZEINFO& szi, HWND hWnd, UINT nID);