Considering the following code :
#include <vector>
#include <iostream>
#include <array>
using namespace std;
int main(){
int* ptr;
ptr = new int(3);
int* stock = *&*&ptr;
ptr = nullptr;
cout << *stock<< endl;
cout << *ptr << endl;
}
that declares a pointer that allocates dynamic memory.
when another var stocks the adress of the memory.
Then, the pointer is deleted but the memory is not erased.
You can still access the memory using the copy of the pointer.
If you then try to access the memory using the pointer, the programs crashes.
I would like to know, if it is possible, knowing that the program will crash, to make a function that : in case of crash, stop the program from closing, and just cout << "some message".
thank you
ps: i know that crash means "unrecoverable error", so my question is more a creative nature.