How can I catch a divide-by-zero error (and not other errors; and to be able to access exception information) in Visual Studio 2008 C++?
I tried this:
C++ does not handle divide-by-zero as an exception, per-se.
Quoting Stroustrup:
"low-level events, such as arithmetic overflows and divide by zero, are assumed to be handled by a dedicated lower-level mechanism rather than by exceptions. This enables C++ to match the behaviour of other languages when it comes to arithmetic. It also avoids the problems that occur on heavily pipelined architectures where events such as divide by zero are asynchronous."
"The Design and Evolution of C++" (Addison Wesley, 1994)
In any case, exceptions are never a replacement for proper precondition handling.
You can not do that using standard C++ as it is not standard C++ exception. It's a structured exception. For the standard C++ exception somebody has to do a throw exception;
from the code.
A good approach would be to use safe object oriented wrappers like SafeInt. It also seems to be integrated in Visual Studio 2010.
update:
If the division-by-zero happens in third party code your only option is SEH or something equivalent as answered by Seb Rose