That is the difference between good and bad pilots, recognising you have made an error before it becomes a fatal one or as in your case a near miss.
Basically, the old adage that "superior pilots use their superior judgement to avoid having to use their superior skills!"