I am studying exception handling in c++ and I run across this problem.
So I have a pointer that is uninitialized and tried deleting it.
When I ran the code the last message 'End' was not deleted.
What I did was read up on exception handling and use try catch blocks but I am not sure why I did not catch up on the error, even if I have a catch all.
I am using windows and mingw as compiler. It just exits without printing anything.
Ohhh, need to take a mental note about this one. Is there somewhere a list of C++ things or transactions that may cause undefined behavior? This would be useful for C++ beginners.
Note that a null pointer is not the same as an uninitialized pointer. For a pointer to be null it has to be initialized to null. Using delete on a null pointer is safe and will do nothing.
Some of the most common causes of undefined behaviour from the top of my head:
* Using uninitialized objects.
* Accessing array elements with an index that is out of bounds.
* Dereferencing pointers that are invalid or null.
* Division by zero.
* Signed integer overflow.
* Reaching the end of a non-void function without return.
* Sometimes passing certain values to functions can be undefined, such as passing a null pointer to std::strlen, or passing INT_MIN to std::abs.