How to execute cleanup code on abort in Runner

Hi,
I’d like my stimulus code to run some cleanup functions when it is aborted from the Experiment Runner. How can I detect an abort command from the “Stop Task” button in runner?
Thanks
Gordon