Consider $F = (\frac{-y}{x^2+y^2},\frac{x}{x^2+y^2})$ defined over the punctuated plane $U=\mathbb{R}^2\setminus\{(0,0)\}$. You can check that it satisfies the "closedness" condition, both $\frac{\partial f}{\partial y}$ and $\frac{\partial g}{\partial x}$ are equal to $\frac{y^2-x^2}{x^2+y^2}$.
Written in polar coordinates we have
$$
F = (-\frac{\sin\theta}{\rho},\frac{\cos\theta}{\rho}).
$$
One might think that $F = \nabla \cdot \theta$ since $\theta = \arctan\frac{y}{x}$ and $\frac{\partial \theta}{\partial x} = \frac{-y}{x^2+y^2}$ and $\frac{\partial \theta}{\partial y} = \frac{x}{x^2+y^2}$, but this reasoning is not correct. The problem is that $\theta$ is not continuous over the whole of $U$. Depending on the definition somewhere will be a jump of $2\pi$. On the other side if we consider $U$ just the right half plane, then we can define $\theta$ to be continuous there (give values in $(-\pi,\pi)$), and $F$ will have a potential.
In general this $F$ doesn't have a potential function. If it had, any integral over a closed curve would give $0$, but ingetrating $F$ over a circle of radius 1 centered in zero gives $2\pi$. You can check this by using the polar coordinate representation.
In general, if a vector function satisfies the closedness condition, then locally in every point, i.e. given a point - in every small neighbourhood, F will have a potential function. What is not true that you can glue up all these potential functions to create a potential function defined over the whole set $U$. This depends on the topology of the set, and generally, if it is unpunctured then a potential exists.
See also Show that the form $w$ is closed but not exact