Possible duplicate:
What is the easiest way to make a C ++ program crash?
There is a construction that I often see in our code base, where the program somehow gets into an invalid state, the code will do something intentionally wrong, just to cause a crash. This usually happens like this:
if(<something is wrong>) { int *ptr = NULL; *ptr = 0; }
This of course leads to a null reference exception and the program crashes in an unrecoverable manner. I'm just wondering if this is really the best way to do this? First of all, it is poorly read. Without comment, you may not understand that an accident occurred here. Secondly, it is almost impossible to restore it. It does not throw an exception, so it cannot be handled by other code. It just kills the program dead without the possibility of a return. It also does not provide much information on why he should have crashed here. And this will happen in all assemblies, in contrast to, say, the statement. (We have a fairly robust claim system, but it is not always used in such cases.)
This is a style that we use everywhere, and I am not able to try to convince anyone else. I just wonder how this is common in the industry.
source share