Dereferencing a
NULL
pointer will cause the
CPU to throw an
hardware exception that usually is handled by the
operating system, and generally is not a good programming style to
catch this kind of exception, instead the best is to test conditions before executing code that could fall in such an exception.
However, if you want to catch this kind of exception, you could do it in three ways (all are
Microsoft specific features):
- translate Win32 exceptions to C++ exceptions using
_set_se_translator
and the C++ try/catch
construct (see http://msdn.microsoft.com/en-us/library/5z4bw5h5(VS.80).aspx[^]); note that you must compile your code with the /EHa switch to make this method working