From 52539b01b952d9edc69c304740525c6f3a0c6190 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 25 May 2010 23:41:58 +0000 Subject: [PATCH] [CLEAN] throw runtime_error instead of int. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@635 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../MISC/PluginsManager/PluginsManager.cpp | 21 ++++++++---- PowerEditor/src/Notepad_plus_Window.cpp | 6 ++-- PowerEditor/src/Parameters.cpp | 22 +++++++----- .../src/ScitillaComponent/FindReplaceDlg.cpp | 3 +- .../src/ScitillaComponent/FindReplaceDlg.h | 2 +- .../src/ScitillaComponent/GoToLineDlg.h | 2 +- .../ScitillaComponent/ScintillaEditView.cpp | 16 +++++---- .../src/ScitillaComponent/columnEditor.h | 2 +- .../WinControls/ColourPicker/ColourPicker.cpp | 2 +- .../WinControls/ColourPicker/ColourPopup.cpp | 3 +- .../WinControls/DockingWnd/DockingManager.cpp | 9 ++--- .../DockingWnd/DockingSplitter.cpp | 6 ++-- .../src/WinControls/DockingWnd/Gripper.cpp | 6 ++-- .../WinControls/ImageListSet/ImageListSet.cpp | 5 +-- .../OpenSaveFileDialog/FileDialog.cpp | 10 +++--- .../SplitterContainer/Splitter.cpp | 26 +++++++------- .../SplitterContainer/SplitterContainer.cpp | 6 ++-- .../WinControls/StaticDialog/StaticDialog.cpp | 2 -- .../src/WinControls/StatusBar/StatusBar.cpp | 3 +- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 22 +++++------- .../src/WinControls/TaskList/TaskList.cpp | 3 +- .../src/WinControls/ToolBar/ToolBar.cpp | 3 +- .../src/WinControls/ToolTip/ToolTip.cpp | 3 +- PowerEditor/src/WinControls/Window.h | 8 ++--- PowerEditor/src/winmain.cpp | 34 +++++++------------ 25 files changed, 102 insertions(+), 123 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index 59540d067..919e9f881 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -183,9 +183,10 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath, vector_pBeNotified(&scNotif); + } catch(std::exception e) { + ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); } catch (...) { TCHAR funcInfo[128]; generic_sprintf(funcInfo, TEXT("notify(SCNotification *notification) : \r notification->nmhdr.code == %d\r notification->nmhdr.hwndFrom == %d\r notification->nmhdr.idFrom == %d"),\ @@ -429,6 +434,8 @@ void PluginsManager::relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam { try { _pluginInfos[i]->_pMessageProc(Message, wParam, lParam); + } catch(std::exception e) { + ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); } catch (...) { TCHAR funcInfo[128]; generic_sprintf(funcInfo, TEXT("relayNppMessages(UINT Message : %d, WPARAM wParam : %d, LPARAM lParam : %d)"), Message, wParam, lParam); @@ -452,6 +459,8 @@ bool PluginsManager::relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lPa { try { _pluginInfos[i]->_pMessageProc(Message, wParam, lParam); + } catch(std::exception e) { + ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); } catch (...) { TCHAR funcInfo[128]; generic_sprintf(funcInfo, TEXT("relayPluginMessages(UINT Message : %d, WPARAM wParam : %d, LPARAM lParam : %d)"), Message, wParam, lParam); diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 81acbc048..e1e60248a 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -45,8 +45,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin if (!::RegisterClass(&nppClass)) { - systemMessage(TEXT("System Err")); - throw int(98); + throw std::runtime_error("Notepad_plus_Window::init : RegisterClass() function failed"); } RECT workAreaRect; @@ -74,8 +73,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(777); + throw std::runtime_error("Notepad_plus_Window::init : CreateWindowEx() function return null"); } gNppHWND = _hSelf; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index f2d1bbcbb..458bf18d2 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2020,8 +2020,6 @@ bool NppParameters::getShortcuts(TiXmlNode *node, Shortcut & sc) } -const int loadFailed = 100; -const int missingName = 101; bool NppParameters::feedUserLang(TiXmlNode *node) { bool isEverythingOK = true; @@ -2035,26 +2033,32 @@ bool NppParameters::feedUserLang(TiXmlNode *node) const TCHAR *ext = (childNode->ToElement())->Attribute(TEXT("ext")); hasFoundElement = true; try { - if (!name || !name[0] || !ext) throw int(missingName); + if (!name || !name[0] || !ext) + throw std::runtime_error("NppParameters::feedUserLang : UserLang name is missing"); _userLangArray[_nbUserLang] = new UserLangContainer(name, ext); _nbUserLang++; TiXmlNode *settingsRoot = childNode->FirstChildElement(TEXT("Settings")); - if (!settingsRoot) throw int(loadFailed); + if (!settingsRoot) + throw std::runtime_error("NppParameters::feedUserLang : Settings node is missing"); + feedUserSettings(settingsRoot); TiXmlNode *keywordListsRoot = childNode->FirstChildElement(TEXT("KeywordLists")); - if (!keywordListsRoot) throw int(loadFailed); + if (!keywordListsRoot) + throw std::runtime_error("NppParameters::feedUserLang : KeywordLists node is missing"); + feedUserKeywordList(keywordListsRoot); TiXmlNode *stylesRoot = childNode->FirstChildElement(TEXT("Styles")); - if (!stylesRoot) throw int(loadFailed); + if (!stylesRoot) + throw std::runtime_error("NppParameters::feedUserLang : Styles node is missing"); + feedUserStyles(stylesRoot); - } catch (int e) { - if (e == loadFailed) - delete _userLangArray[--_nbUserLang]; + } catch (std::exception e) { + delete _userLangArray[--_nbUserLang]; isEverythingOK = false; } } diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index 0c87059fe..742ebbe2e 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -2188,7 +2188,8 @@ void FindIncrementDlg::init(HINSTANCE hInst, HWND hPere, FindReplaceDlg *pFRDlg, { Window::init(hInst, hPere); if (!pFRDlg) - throw int(9910); + throw std::runtime_error("FindIncrementDlg::init : Parameter pFRDlg is null"); + _pFRDlg = pFRDlg; create(IDD_INCREMENT_FIND, isRTL); _isRTL = isRTL; diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h index d0eff9579..cde9c761f 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -167,7 +167,7 @@ public : void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { Window::init(hInst, hPere); if (!ppEditView) - throw int(9900); + throw std::runtime_error("FindIncrementDlg::init : ppEditView is null."); _ppEditView = ppEditView; }; diff --git a/PowerEditor/src/ScitillaComponent/GoToLineDlg.h b/PowerEditor/src/ScitillaComponent/GoToLineDlg.h index f341ab81a..8b1628760 100644 --- a/PowerEditor/src/ScitillaComponent/GoToLineDlg.h +++ b/PowerEditor/src/ScitillaComponent/GoToLineDlg.h @@ -34,7 +34,7 @@ public : void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { Window::init(hInst, hPere); if (!ppEditView) - throw int(9900); + throw std::runtime_error("GoToLineDlg::init : ppEditView is null."); _ppEditView = ppEditView; }; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 1beef406f..28e370fd7 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -143,8 +143,7 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) { if (!_hLib) { - MessageBox( NULL, TEXT("Can not load the dynamic library"), TEXT("SCINTILLA ERROR : "), MB_OK | MB_ICONSTOP); - throw int(106901); + throw std::runtime_error("ScintillaEditView::init : SCINTILLA ERROR - Can not load the dynamic library"); } Window::init(hInst, hPere); @@ -161,8 +160,7 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) if (!_hSelf) { - systemMessage(TEXT("System Error")); - throw int(106901); + throw std::runtime_error("ScintillaEditView::init : CreateWindowEx() function return null"); } _pScintillaFunc = (SCINTILLA_FUNC)::SendMessage(_hSelf, SCI_GETDIRECTFUNCTION, 0, 0); @@ -170,10 +168,14 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) _userDefineDlg.init(_hInst, _hParent, this); - if (!_pScintillaFunc || !_pScintillaPtr) + if (!_pScintillaFunc) { - systemMessage(TEXT("System Err")); - throw int(106901); + throw std::runtime_error("ScintillaEditView::init : SCI_GETDIRECTFUNCTION message failed"); + } + + if (!_pScintillaPtr) + { + throw std::runtime_error("ScintillaEditView::init : SCI_GETDIRECTPOINTER message failed"); } execute(SCI_SETMARGINMASKN, _SC_MARGE_FOLDER, SC_MASK_FOLDERS); diff --git a/PowerEditor/src/ScitillaComponent/columnEditor.h b/PowerEditor/src/ScitillaComponent/columnEditor.h index f539850d5..2206b9093 100644 --- a/PowerEditor/src/ScitillaComponent/columnEditor.h +++ b/PowerEditor/src/ScitillaComponent/columnEditor.h @@ -37,7 +37,7 @@ public : void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { Window::init(hInst, hPere); if (!ppEditView) - throw int(9900); + throw std::runtime_error("StaticDialog::init : ppEditView is null."); _ppEditView = ppEditView; }; diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp index 6a28355ea..6e9ceaecc 100644 --- a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp @@ -37,7 +37,7 @@ void ColourPicker::init(HINSTANCE hInst, HWND parent) if (!_hSelf) { systemMessage(TEXT("System Err")); - throw int(6969); + throw std::runtime_error("ColourPicker::init : CreateWindowEx() function return null"); } diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp index c0f148b53..30de6f7d6 100644 --- a/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp @@ -36,8 +36,7 @@ void ColourPopup::create(int dialogID) if (!_hSelf) { - systemMessage(TEXT("ColourPopup")); - throw int(696); + throw std::runtime_error("ColourPopup::create : CreateDialogParam() function return null"); } Window::getClientRect(_rc); display(); diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingManager.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingManager.cpp index fa025f480..0b6f54bfd 100644 --- a/PowerEditor/src/WinControls/DockingWnd/DockingManager.cpp +++ b/PowerEditor/src/WinControls/DockingWnd/DockingManager.cpp @@ -105,8 +105,7 @@ void DockingManager::init(HINSTANCE hInst, HWND hWnd, Window ** ppWin) if (!::RegisterClass(&clz)) { - systemMessage(TEXT("System Err")); - throw int(98); + throw std::runtime_error("DockingManager::init : RegisterClass() function failed"); } _isRegistered = TRUE; } @@ -125,8 +124,7 @@ void DockingManager::init(HINSTANCE hInst, HWND hWnd, Window ** ppWin) if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(777); + throw std::runtime_error("DockingManager::init : CreateWindowEx() function return null"); } setClientWnd(ppWin); @@ -152,8 +150,7 @@ void DockingManager::init(HINSTANCE hInst, HWND hWnd, Window ** ppWin) if (!gWinCallHook) { - systemMessage(TEXT("System Err")); - throw int(1000); + throw std::runtime_error("DockingManager::init : SetWindowsHookEx() function return null"); } _dockData.hWnd = _hSelf; diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.cpp index a47ca21ef..a089cc35e 100644 --- a/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.cpp +++ b/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.cpp @@ -87,8 +87,7 @@ void DockingSplitter::init(HINSTANCE hInst, HWND hWnd, HWND hMessage, UINT flags if (!::RegisterClass(&wc)) { - systemMessage(TEXT("System Err")); - throw int(98); + throw std::runtime_error("DockingSplitter::init : RegisterClass() function failed"); } else if (flags & DMS_HORIZONTAL) { @@ -107,8 +106,7 @@ void DockingSplitter::init(HINSTANCE hInst, HWND hWnd, HWND hMessage, UINT flags if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(777); + throw std::runtime_error("DockingSplitter::init : CreateWindowEx() function return null"); } } diff --git a/PowerEditor/src/WinControls/DockingWnd/Gripper.cpp b/PowerEditor/src/WinControls/DockingWnd/Gripper.cpp index 0643983d3..51ec3aa7d 100644 --- a/PowerEditor/src/WinControls/DockingWnd/Gripper.cpp +++ b/PowerEditor/src/WinControls/DockingWnd/Gripper.cpp @@ -129,8 +129,7 @@ void Gripper::startGrip(DockingCont* pCont, DockingManager* pDockMgr) if (!::RegisterClass(&clz)) { - systemMessage(TEXT("System Err")); - throw int(98); + throw std::runtime_error("Gripper::startGrip : RegisterClass() function failed"); } _isRegistered = TRUE; } @@ -149,8 +148,7 @@ void Gripper::startGrip(DockingCont* pCont, DockingManager* pDockMgr) if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(777); + throw std::runtime_error("Gripper::startGrip : CreateWindowEx() function return null"); } } diff --git a/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp index 41cb03a5a..0ba57537e 100644 --- a/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp +++ b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp @@ -25,7 +25,7 @@ void IconList::create(HINSTANCE hInst, int iconSize) _iconSize = iconSize; _hImglst = ImageList_Create(iconSize, iconSize, ILC_COLOR32 | ILC_MASK, 0, nbMax); if (!_hImglst) - throw int(25); + throw std::runtime_error("IconList::create : ImageList_Create() function return null"); }; void IconList::create(int iconSize, HINSTANCE hInst, int *iconIDArray, int iconIDArraySize) @@ -42,7 +42,8 @@ void IconList::addIcon(int iconID) const { HICON hIcon = ::LoadIcon(_hInst, MAKEINTRESOURCE(iconID)); if (!hIcon) - throw int(26); + throw std::runtime_error("IconList::addIcon : LoadIcon() function return null"); + ImageList_AddIcon(_hImglst, hIcon); ::DestroyIcon(hIcon); }; diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp index d8a84f068..4b4a060ac 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp @@ -168,8 +168,9 @@ TCHAR * FileDialog::doOpenSingleFileDlg() ::GetCurrentDirectory(MAX_PATH, dir); params->setWorkingDir(dir); } - } - catch(...) { + } catch(std::exception e) { + ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); + } catch(...) { ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); } @@ -247,8 +248,9 @@ TCHAR * FileDialog::doSaveDlg() ::GetCurrentDirectory(MAX_PATH, dir); params->setWorkingDir(dir); } - } - catch(...) { + } catch(std::exception e) { + ::MessageBoxA(NULL, e.what(), "Exception", MB_OK); + } catch(...) { ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); } diff --git a/PowerEditor/src/WinControls/SplitterContainer/Splitter.cpp b/PowerEditor/src/WinControls/SplitterContainer/Splitter.cpp index da6dc39ec..f68417c28 100644 --- a/PowerEditor/src/WinControls/SplitterContainer/Splitter.cpp +++ b/PowerEditor/src/WinControls/SplitterContainer/Splitter.cpp @@ -40,6 +40,15 @@ Splitter::Splitter() : Window() void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize, int iSplitRatio, DWORD dwFlags) { + if (hPere == NULL) + { + throw std::runtime_error("Splitter::init : Parameter hPere is null"); + } + if (iSplitRatio < 0) + { + throw std::runtime_error("Splitter::init : Parameter iSplitRatio shoulds be 0 < ratio < 100"); + } + Window::init(hInst, hPere); _spiltterSize = splitterSize; @@ -47,16 +56,7 @@ void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize, DWORD dwExStyle = 0L; DWORD dwStyle = WS_CHILD | WS_VISIBLE; - if (hPere == NULL) - { - ::MessageBox(NULL, TEXT("pas de pere?"), TEXT("Splitter::init"), MB_OK); - throw int(96); - } - if (iSplitRatio < 0) - { - ::MessageBox(NULL, TEXT("it shoulds be 0 < ratio < 100"), TEXT("Splitter::init"), MB_OK); - throw int(96); - } + _hParent = hPere; _dwFlags = dwFlags; @@ -70,8 +70,7 @@ void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize, if (iSplitRatio >= 100) { //cant be 100 % or more - ::MessageBox(NULL, TEXT("it shoulds be 0 < ratio < 100"), TEXT("Splitter::init"), MB_OK); - throw int(96); + throw std::runtime_error("Splitter::init : Parameter iSplitRatio shoulds be 0 < ratio < 100"); } } @@ -188,8 +187,7 @@ void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize, if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(345); + throw std::runtime_error("Splitter::init : CreateWindowEx() function return null"); } RECT rc; diff --git a/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.cpp b/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.cpp index d47711797..deb9c4925 100644 --- a/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.cpp +++ b/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.cpp @@ -55,8 +55,7 @@ void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize, if (!::RegisterClass(&splitterContainerClass)) { - systemMessage(TEXT("System Err")); - throw int(98); + throw std::runtime_error(" SplitterContainer::create : RegisterClass() function failed"); } _isRegistered = true; } @@ -75,8 +74,7 @@ void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize, if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(777); + throw std::runtime_error(" SplitterContainer::create : CreateWindowEx() function return null"); } } diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp index 3c25ccea9..0cfdecb2e 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -99,8 +99,6 @@ void StaticDialog::create(int dialogID, bool isRTL) if (!_hSelf) { - //systemMessage(TEXT("StaticDialog")); - //throw int(666); return; } diff --git a/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp b/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp index 2605ee410..6b671b8e5 100644 --- a/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp +++ b/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp @@ -41,8 +41,7 @@ void StatusBar::init(HINSTANCE hInst, HWND hPere, int nbParts) if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(9); + throw std::runtime_error("StatusBar::init : CreateWindowEx() function return null"); } _nbParts = nbParts; diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index e5499d9a1..edd042411 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -61,10 +61,10 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTraditio int multiLine = isMultiLine?(_isTraditional?TCS_MULTILINE:0):0; int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |\ - /* WS_BORDER |*/TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine; + TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine; _hSelf = ::CreateWindowEx( - 0/*TCS_EX_FLATSEPARATORS*/ , + 0, WC_TABCONTROL, TEXT("Tab"), style, @@ -76,8 +76,7 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTraditio if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(69); + throw std::runtime_error("TabBar::init : CreateWindowEx() function return null"); } } @@ -239,13 +238,10 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTrad int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |\ TCS_TOOLTIPS | TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine; - //if (isOwnerDrawTab() && (!_isTraditional)) - { - style |= TCS_OWNERDRAWFIXED; - //printStr(TEXT("ownerDraw")); - } + style |= TCS_OWNERDRAWFIXED; + _hSelf = ::CreateWindowEx( - /*TCS_EX_FLATSEPARATORS */0, + 0, WC_TABCONTROL, TEXT("Tab"), style, @@ -257,8 +253,7 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTrad if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(69); + throw std::runtime_error("TabBarPlus::init : CreateWindowEx() function return null"); } if (!_isTraditional) { @@ -277,9 +272,8 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTrad if (!found) { _ctrlID = -1; - ::MessageBox(NULL, TEXT("The nb of Tab Control is over its limit"), TEXT("Tab Control err"), MB_OK); destroy(); - throw int(96); + throw std::runtime_error("TabBarPlus::init : Tab Control error - Tab Control # is over its limit"); } _hwndArray[i] = _hSelf; _ctrlID = i; diff --git a/PowerEditor/src/WinControls/TaskList/TaskList.cpp b/PowerEditor/src/WinControls/TaskList/TaskList.cpp index 7e62c389e..baf0a432f 100644 --- a/PowerEditor/src/WinControls/TaskList/TaskList.cpp +++ b/PowerEditor/src/WinControls/TaskList/TaskList.cpp @@ -55,8 +55,7 @@ void TaskList::init(HINSTANCE hInst, HWND parent, HIMAGELIST hImaLst, int nbItem NULL); if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(69); + throw std::runtime_error("TaskList::init : CreateWindowEx() function return null"); } ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp index c4b74bd45..624c1583b 100644 --- a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -228,8 +228,7 @@ void ToolBar::reset(bool create) if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(9); + throw std::runtime_error("ToolBar::reset : CreateWindowEx() function return null"); } if (_state != TB_STANDARD) diff --git a/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp b/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp index 15742b316..8ad01c5f9 100644 --- a/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp +++ b/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp @@ -35,8 +35,7 @@ void ToolTip::init(HINSTANCE hInst, HWND hParent) CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL ); if (!_hSelf) { - systemMessage(TEXT("System Err")); - throw int(6969); + throw std::runtime_error("ToolTip::init : CreateWindowEx() function return null"); } ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); diff --git a/PowerEditor/src/WinControls/Window.h b/PowerEditor/src/WinControls/Window.h index bb4e01e52..4498e2f05 100644 --- a/PowerEditor/src/WinControls/Window.h +++ b/PowerEditor/src/WinControls/Window.h @@ -81,7 +81,7 @@ public: }; HWND getHSelf() const { - //assert(_hSelf); + assert(_hSelf != 0); return _hSelf; }; @@ -94,11 +94,7 @@ public: }; HINSTANCE getHinst() const { - if (!_hInst) - { - ::MessageBox(NULL, TEXT("_hInst == NULL"), TEXT("class Window"), MB_OK); - throw int(1999); - } + assert(_hInst != 0); return _hInst; }; protected: diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 9484508af..e7e18bdf8 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -367,36 +367,26 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) } } } catch(int i) { - if (i == 106901) - ::MessageBox(NULL, TEXT("Scintilla.init is failed!"), TEXT("Notepad++ Exception: 106901"), MB_OK); - else { - TCHAR str[50] = TEXT("God Damned Exception : "); - TCHAR code[10]; - wsprintf(code, TEXT("%d"), i); - ::MessageBox(Notepad_plus_Window::gNppHWND, lstrcat(str, code), TEXT("Notepad++ Exception"), MB_OK); - doException(notepad_plus_plus); - } + TCHAR str[50] = TEXT("God Damned Exception : "); + TCHAR code[10]; + wsprintf(code, TEXT("%d"), i); + ::MessageBox(Notepad_plus_Window::gNppHWND, lstrcat(str, code), TEXT("Int Exception"), MB_OK); + doException(notepad_plus_plus); + } catch(std::runtime_error & ex) { + ::MessageBoxA(Notepad_plus_Window::gNppHWND, ex.what(), "Runtime Exception", MB_OK); + doException(notepad_plus_plus); } catch (const Win32Exception & ex) { TCHAR message[1024]; //TODO: sane number wsprintf(message, TEXT("An exception occured. Notepad++ cannot recover and must be shut down.\r\nThe exception details are as follows:\r\n") -#ifdef UNICODE - TEXT("Code:\t0x%08X\r\nType:\t%S\r\nException address: 0x%08X"), -#else - TEXT("Code:\t0x%08X\r\nType:\t%s\r\nException address: 0x%08X"), -#endif - ex.code(), ex.what(), ex.where()); + TEXT("Code:\t0x%08X\r\nType:\t%S\r\nException address: 0x%08X"), ex.code(), ex.what(), ex.where()); ::MessageBox(Notepad_plus_Window::gNppHWND, message, TEXT("Win32Exception"), MB_OK | MB_ICONERROR); mdump.writeDump(ex.info()); doException(notepad_plus_plus); - } catch(std::exception ex) { -#ifdef UNICODE - const wchar_t * text = WcharMbcsConvertor::getInstance()->char2wchar(ex.what(), CP_ACP); - ::MessageBox(Notepad_plus_Window::gNppHWND, text, TEXT("C++ Exception"), MB_OK); -#else - ::MessageBox(Notepad_plus_Window::gNppHWND, ex.what(), TEXT("C++ Exception"), MB_OK); -#endif + } catch(std::exception & ex) { + ::MessageBoxA(Notepad_plus_Window::gNppHWND, ex.what(), "General Exception", MB_OK); doException(notepad_plus_plus); } catch(...) { //this shouldnt ever have to happen + ::MessageBoxA(Notepad_plus_Window::gNppHWND, "An exception that we did not yet found its name is just caught", "Unknown Exception", MB_OK); doException(notepad_plus_plus); }