From Longman Dictionary of Contemporary Englishcatch yourself doing somethingcatch yourself doing somethingREALIZEto suddenly realize you are doing something Standing there listening to the song, he caught himself smiling from ear to ear. → catch
Examples from the Corpus
catch yourself doing something• I caught myself watching everybody else instead of paying attention to the lecture.