Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <execinfo.h>
- #include <signal.h>
- using namespace std;
- void handler(int sig) {
- void *array[10];
- size_t size;
- // get void*'s for all entries on the stack
- size = backtrace(array, 10);
- // print out all the frames to stderr
- fprintf(stderr, "Error: signal %d:\n", sig);
- backtrace_symbols_fd(array, size, 2);
- exit(1);
- }
- main()
- {
- signal(SIGSEGV,handler);
- try
- {
- for(int i=0; true; i++)
- {
- char* temp=new char[1000000];
- cout << i << ' ' << (void*)temp << endl;
- //delete[] temp;
- }
- }
- catch(bad_alloc& ba)
- {
- cerr << "bad_alloc caught: " << ba.what() << endl;
- while(1) {};
- //exit(1);
- }
- }
Add Comment
Please, Sign In to add comment