> As it should be expected, this program terminates with a message
> appearing: Instruction at address 0x0040100e referenced memory at
> address 0x00000190. If one uncomment the try ... catch statement
> the message should not appear and the program should exit normally.
> And it's so if I use MS Visual Studio compiler. But g++ doesn't
> handle the exception: the pop up message appears in any case.
> Is it a g++ feature or I don't undestand anything?
Both compilers (MSVC and MINGW) are OK. Referencing memory that doesn't
belong to program invokes undefined behaviour, which means that program
may do anything. Current version of MSVC throws operating system
exception (so called "SEH") which can be consumed by "catch (...)", as
C++ exception handling mechanism used in MSVC depends on SEH - but that
behaviour is specific to compiler. AFAIK it may change in next version
of Visual Studio when compiling C++ with specific options (due to
performance reasons, I think). On the other hand, MINGW is not using SEH
as C++ exception handling mechanism, which means that "catch (...)" will
ignore any operating system exception - effectively these exceptions
will be handled separately (by runtime or operating system). This is
also fine, valid behaviour per C++ standard. Other perfectly valid
result would be to destroy all data on your hard drive or send report to
your boss - undefined behaviour means that anything may happen and
compiler won't waste precious CPU time trying to prevent you from
shooting your foot.
I would be worried if MINGW behaviour is incosistent between platforms
where GCC has been already ported; but if the same behaviour (eg. core
dump) is exposed on other platforms, MINGW is right in respect to
programmers expectations. But still that's not obligatory; it's just an
issue of consistency between GCC ports. And you are wrong expecting that
undefined behaviour will invoke similar results in different compilers.