Sunday, 18 August 2013

Will throwing an exception for bad pointer access ever be standard behavior in C++?

Will throwing an exception for bad pointer access ever be standard
behavior in C++?

I did a quick search on Google and wasn't able to find anything relevant
to this exact topic.
As C++ continues to move toward being a more modern language, including
lambdas, range based for loops, etc, it seems like this question may
eventually come up, if it hasn't already.
I don't see how this could be anything but a good thing, and provide the
same benefits that have been proven useful in C++/CLI, C#, Java, etc. And
if anyone didn't want this behavior, It could simply be made optional, and
turned off with a compiler setting, the same way one would disable
standard exceptions or RTTI.
Also, it has been suggested, but discouraged that one could create a
signal handler for SIGSEGV and throw an exception from there, to simulate
the suggested behavior. Now, although this is a bit of a hack, and not
guaranteed to work on all platforms, how hard could it really be to
implement null reference exceptions in C++ if the same basic behavior can
be simulated(non-standardly) with around 10 lines of code?
So, is there any reason that throwing an exception for bad pointer access
couldn't eventually become part of the standard in the future?

No comments:

Post a Comment