Added exceptions in case of errors. Fixes #8915.