Use $dialog automatically halts the script, might not work with on exit though. Give it a try.