Improve handling of doctrine exceptions