How to catch error when program crash?
c
Solution
Though it is undefined behavior, you can use this if you're getting segmentation fault.
#include <signal.h>
#include <stdio.h>
void Segfault_Handler(int signo)
{
fprintf(stderr,"\n[!] Oops! Segmentation fault...\n");
}
int main() {
signal(SIGSEGV,Segfault_Handler);
return 0;
}
Problem
How to catch error when program crashes? Example - Java when crash writes an error log to file. I writed this code to cause an error: ``` int * invalidPointer = NULL; printf("%d\n", invalidPointer[0]); ``` And java crashes and saving an error log (hs_error_pid(pid).log) to file, I want to handle an error in program written with C (not in Java, this is only example) Second example - Chrome when crashes shows information and we can restart browser by clicking yes.