Improving the exception handling to be more consistent