Suggested by Campbell, thanks! Also moved the exception into own function and improved comments. Fixes T53008.