making error catching generic