Catch a Memory Access Violation in C++
From: https://stackoverflow.com/questions/16612444/catch-a-memory-access-violation-in-c
In C++, is there a standard way (or any other way, for that matter) to catch an exception triggered by a memory access violation?
For example, if something went wrong and the program tried to access something that it wasn't supposed to, how would you get an error message to appear saying "Memory Access Violation!" instead of just terminating the process and not showing the user any information about the crash?
I'm programming a game for Windows using MinGW, if that helps any.
[Answer]
Access violationis a hardware exception and cannot be caught by a standard
try...catch.
Since the handling of hardware-exception are system specific, any solution to catch it inside the code would also be system specific.
On Unix/Linux you could use a SignalHandler
to do catch the SIGSEGV
signal.
On Windows you could catch these structured exception using the __try/__except
statement.
- how to catch out of memory exception in c++
- Unhandled exception at 0x00000000 in CallDll.exe: 0xC0000005: Access violation reading location 0x00
- System.AccessViolationException: Attempted to read or write protected memory This is often an indication that other memory is corrupt
- OpenCV memory leaking management in C/C++ (OpenCV 内存泄露)
- catch access violation exception
- Top 5 common mistakes to cause memory leaks in Symbian C++ applications
- Memory Leak Detection in C++
- Part1: Overcome the ‘Access Violation Exception’ in the FFMPEG
- 遇到"Unhandled exception in app.exe (QTGUID4.DLL): 0xC0000005: Access Violation"错误的解决过程
- First-chance exception at 0x774CEB23 (ntdll.dll) in XXX.exe: 0xC0000005: Access violation writing
- 解决VC 类向导添加变量后莫名其妙出现 Unhandled exception in xxx.exe:0xC0000005:Access Violation错误的问题
- How to programmatically clear the filesystem memory cache in C++ on a Linux system?
- C语言:sizeof导致的Memory access violation
- SIGBUS:BUS_ADRERR for stack access violation in memcpy
- Error: Exception was raised when calling event-notify Vuser function in extension parameng.dll: System Exceptions: EXCEPTION_ACCESS_VIOLATION
- oracle 错误 access violation at address in module 'ora805.dll'. write of address
- "Unhandled exception in app.exe (QtGuid4.dll): 0xC0000005: Access Violation"错误解决
- throw...catch in c++
- Part2: Overcome the ‘Access Violation Exception’ in the FFMPEG
- laravel 5.4 报错SQLSTATE[42000] Syntax error or access violation 1055 'xxx' isn't in GROUP BY