fatal execution of program

  I know that in C++ you can use try catch blocks to catch fatal errors.
How can you do this in C.

If my porgram is running, and terminates with a fatal error, then
I want to write information to a file before the program terminates.
Does anyone know how to do this?

Thanks in advance.

Bill