Issue #16714: use 'raise' exceptions, don't 'throw'.

Patch by Serhiy Storchaka.