suppose a project with Arduino that we should save battery power, so we use sleep mode and also avoiding the Arduino of hanging and use watchdog timer. But the problem is here that when the Arduino goes to sleep the watchdog timer never(or cant be) reset again because of sleep and it will overflow over and over and reset the Arduino over and over. so what do you suggest to solve this problem, I mean running sleep mode and watchdog timer at the same time in a code?
When you sleep the Arduino is locked up. So yes, the watchdog timer will time out and reset the Arduino.
But, since you're in sleep mode, it's not so much a "reboot" as a "wakeup".
The watchdog timer is one of the normal ways of waking up periodically to do things. If you want to use the watchdog for its other "anti-lockup" purpose then you will have to arrange some other way of waking up before the watchdog is due to expire so you can "kick" it.
Or you disable the watchdog entirely before going to sleep so that the only wakeup source is whatever source you have configured. Then you can turn the watchdog on again when you wake up.
However that probably means that the watchdog is useless, since chances are you won't be awake for long enough periods for the watchdog to have any effect.
Sleeping and using the internal watchdog as a watchdog are pretty much mutually exclusive. If you sleep, then the watchdog is a periodic wake-up source.
Either set the watchdog to 8s, and setup the WDT interrupt. And deal with the fact that the MCU wakes up every 8s. You could have it go back to sleep, unless a button is pressed, or something. The extra power usage for these short wakeups is negligible in most cases.
Or disable the watchdog right before sleeping, and enable right after waking up. And hope the MCU never hangs in between.