Improve error reporting

Follow-up of changes introduced in commit 72c922668fefc1cf671d9c9e38ebf22a22a80dcf
Merge pull request #2801 from VojtechVitek/checkError

Improve error reporting