Guest User

Untitled

a guest
Jan 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <execinfo.h>
  5. #include <signal.h>
  6.  
  7. using namespace std;
  8.  
  9. void handler(int sig) {
  10. void *array[10];
  11. size_t size;
  12.  
  13. // get void*'s for all entries on the stack
  14. size = backtrace(array, 10);
  15.  
  16. // print out all the frames to stderr
  17. fprintf(stderr, "Error: signal %d:\n", sig);
  18. backtrace_symbols_fd(array, size, 2);
  19. exit(1);
  20. }
  21.  
  22. main()
  23. {
  24. signal(SIGSEGV,handler);
  25. try
  26. {
  27. for(int i=0; true; i++)
  28. {
  29. char* temp=new char[1000000];
  30. cout << i << ' ' << (void*)temp << endl;
  31. //delete[] temp;
  32. }
  33. }
  34. catch(bad_alloc& ba)
  35. {
  36. cerr << "bad_alloc caught: " << ba.what() << endl;
  37. while(1) {};
  38. //exit(1);
  39. }
  40. }
Add Comment
Please, Sign In to add comment