I use a poorly written third-party (C / C ++) Api. I used it from managed code (C ++ / CLI). Receive sometimes "access violation errors". And this is the crash of the entire application. I know that I canβt deal with these errors [what can I do if the pointer enters an illegal memory location, etc.).
But I do not want my request to depend on the whole. At least if there is a real problem, my application should gracefully say βOK. I canβt do my work .BYE.β :-), then it least performs some alternative scene and finally closes itself.
But there seems to be no way to catch (maybe a wrong term, a harsh word may be reported) about access violation and similar errors. Is there any way to get information about these errors. Therefore, I can complete my alternative scene.
PS: standard exception handling does not solve this.
#include "stdafx.h" #include <iostream> using namespace System; using namespace std; static void ThrowingManagedException() { throw gcnew ArgumentException("For no good reason"); } static void ThrowingNativeException() { throw std::exception("For no good reason"); } static void SomeBadThingsHappen() { short a[1]; a[0]=1; a[2]= 2; // SomeOne make stupid mistake } int main(array<System::String ^> ^args) { Console::WriteLine(L"Test Exceptions"); try { SomeBadThingsHappen(); //ThrowingNativeException(); //ThrowingManagedException(); } catch(Exception^ e) { Console::WriteLine("Something awful happened: "+ e); } Console::WriteLine("Press enter to exit"); Console::Read(); return 0; }
source share