Stepping through code at source code is not an exact science, unfortunately.
If, as I suspect, the quit is being queued until the code becomes inactive,
then it possibly becomes inactive at the end of the debug "step" in order to
accept your next command, and encounters the quit instead.