I'm doing this exercise where I know that a function $f$ that is holomorphic in $U \cup V$, has a holomorphic antiderivative in $U$ and also another holomorphic antiderivative in $V$, where $U, V \subseteq \mathbb{C}$ are open sets such that $U \cap V \neq \emptyset$ and $U \cap V$ is connected.
Then the question is to prove that $f$ has a holomorphic antiderivative in the union $U \cup V$, and provide a counterexample to show that the hypothesis on the intersection $U \cap V$ are required for the result to be true.
My attempt
I thought that since there are holomorphic functions $F: U \rightarrow \mathbb{C}$ and $G: V \rightarrow \mathbb{C}$ such that F' = f in $U$ and G' = f in $V$, then in the intersection both derivatives coincide so in $U \cap V$ we have F' = G' and so $F = G + C$ in $U \cap V$, where $C$ is a constant. But now my problem is that I don't see how to extend this to the whole union $U \cup V$, and I don't see where I'll use the connectedness assumption.
So if you could help me with my argument I would be most grateful. By the way, if you could also give me a hint to construct a counterexample that would be great. Thanks.