Change autoclass to autoexception - cherry pick from master

Fixes #1388 or part thereof