Backport PR #4372: Don't assume that SyntaxTB is always called with a SyntaxError

closes #5184
1.2.1 what's new