I don't believe that run_on_exit didn't provide the exit code. Maybe you meant it was zero?
If the exit code is zero, then you're still not setting it to something other than zero. It's hard to tell what you're doing wrong if you don't show me what you did. What value did you pass to exit?