Hello Li,
A similar method of examining whether a stack overflow condition does occur is to initialise a specific, say 16-bit value at the bottom of the stack. Then at a single position within the main loop, this RAM location can be tested, and if different from the initialised value, a stack overflow event can be flagged during the normal operation of the code. The test value might then be re-initialised by the test code.
Any variables that might be required for the flagging process should be located in zero page RAM, so that they will not be over-written.
Regards,
Mac