title: detect program termination (C, Windows)
body: <p>I have a program that has to perform certain tasks before it finishes. The problem is that sometimes the program crashes with an exception (like database cannot be reached, etc).
  Now, is there any way to detect an abnormal termination and execute some code before it dies?</p>
  
  <p>Thanks.</p>
  
  <p>code is appreciated.</p>