52189: refractor unreachable Runtime Error (#85725)
Fixes #52189
Since the PR #52228 had gone cold. I made the requested changes and fixed the linting error.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85725
Approved by: https://github.com/lezcano