How to auto save before watchdog restart ?

Hi
I have the following situation: Watchdog is enabled on the Uno which is calculating some variable.
For multiple reasons the Uno hangs from time to time. This is where the watchdog kicks in, restarts the module and the value of the variable is lost, which is not fun at all.
For the time being I am saving the value of that variable in each iteration in EEPROM but this has two problems:
1- From what I understood, I have like 100000 writes before that EEPROM address is burned out.
2- EEPROM writing takes sometime by itself and it adds up to the total delay.

So I am wondering can I have another routine (function) to be called/activated when the module hangs i.e., when the arduino hangs call some function (to save to EEPROM) and then restart.

Any ideas, comments, about how to do that?

Note: streaming the value of the variable via ethernet (i.e. to store it somewhere else and then restoring) is not an option as the scenario is more complex than I described.

Thx.
Mike

So I am wondering can I have another routine (function) to be called/activated when the module hangs i.e., when the arduino hangs call some function (to save to EEPROM) and then restart.

You could. You would just need to figure when the module is going to hang, and call the new routine just before it happens.

Of course, using the watchdog mechanism is a crutch. You should fix the problem(s) that cause the Arduino to appear to hang.

The watchdog was three modes. In one mode it resets the board. In another mode it calls an interrupt. And in the third mode it calls the interrupt the first time and then resets the board on the second timeout.

If you use the last mode there then you can set up your interrupt to save your values and then hold in a busy loop until the second timeout resets the board.

See section 11.8 of the Holy Datasheet for more information.