Improved exception handling
Merge pull request #286 from SammyK/improved-exception-handling

[4.1] Improved exception handling