How to catch integer division by zero and exception of access violation in native C ++

I need to catch an integer to zero and gain access to read or write protected memory and display my own dialog and do something suitable. This exception cannot be caught by the try {} catch {} method, because the hardware throws these exceptions. How can I catch exceptions there? Any suggestions or links to related articles are evaluated by mr.abzadeh

+6
source share
3 answers

It is strange that it is not possible to catch these exceptions. but if so, then I think you can put your own checks and throw your own exceptions. But again, you can miss something ...

+1
source

See the documentation for the __try / __except mechanism. This is used on Windows to detect hardware exceptions.

+8
source

There is a very simple way to catch any exception (division by zero, violation of access rights, etc.) in Visual Studio using try -> catch (...) block :)

A small project setup is enough. Just enable / EHa in the project settings. See Project Properties -> C / C ++ -> Code Generation -> Change C ++ Exception Exceptions to "Yes with SEH Exceptions" . What is it!

See here for more details: http://msdn.microsoft.com/en-us/library/1deeycx5 (v = vs .80) .aspx

+2
source

Source: https://habr.com/ru/post/898817/


All Articles