Preserve errno when throw an exception.