Fixed null error pointer reference for catching errors