Some clean-up and simplification for JobObject class.
[MUtilities.git] / src / ErrorHandler_Win32.cpp
blob4d881b41f0faae28dc4ab95b1dccf71f11d12b0c
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
22 //MUtils
23 #include <MUtils/ErrorHandler.h>
24 #include <MUtils/OSSupport.h>
26 //Win32 API
27 #define WIN32_LEAN_AND_MEAN 1
28 #include <Windows.h>
30 //CRT
31 #include <csignal>
33 ///////////////////////////////////////////////////////////////////////////////
34 // CALLBACK FUNCTIONS
35 ///////////////////////////////////////////////////////////////////////////////
37 // Invalid parameters handler
38 static void my_invalid_param_handler(const wchar_t* exp, const wchar_t* fun, const wchar_t* fil, unsigned int, uintptr_t)
40 MUtils::OS::fatal_exit(L"Invalid parameter handler invoked, application will exit!");
43 // Signal handler
44 static void my_signal_handler(int signal_num)
46 signal(signal_num, my_signal_handler);
47 MUtils::OS::fatal_exit(L"Signal handler invoked, application will exit!");
50 // Global exception handler
51 static LONG WINAPI my_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo)
53 MUtils::OS::fatal_exit(L"Unhandeled exception handler invoked, application will exit!");
54 return LONG_MAX;
57 ///////////////////////////////////////////////////////////////////////////////
58 // SETUP ERROR HANDLERS
59 ///////////////////////////////////////////////////////////////////////////////
61 void MUtils::ErrorHandler::initialize(void)
63 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
64 SetUnhandledExceptionFilter(my_exception_handler);
65 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
66 _set_invalid_parameter_handler(my_invalid_param_handler);
67 SetDllDirectoryW(L""); /*don'tload DLL from "current" directory*/
69 static const int signal_num[6] = { SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
71 for(size_t i = 0; i < 6; i++)
73 signal(signal_num[i], my_signal_handler);
78 ///////////////////////////////////////////////////////////////////////////////