It is very common to use the formula $$x^{\frac{b}{c}} = (x^b)^\frac{1}{c}$$ to simplify the evaluation of a fractional exponent.
I want to know what circumstances allow us to do this step. For example, it does not work in this situation: $$(-4)^{\frac{2}{4}} = ((-4)^2)^\frac{1}{4} = 16^\frac{1}{4} = 2$$ The correct answer is $2i$, but the formula yields $2$. What caused it to go awry here, and in the general case, how can we avoid errors occurring for this reason?
By definition $x^{\alpha}$ is equal to $\textrm{exp}(\alpha \, \textrm{log} \, x)$. So by definition it is not defined if $x$ is not a in $\mathbb R^*_+$. As a consequence, you cannot say that $\sqrt{-4} = 2i$ is the correct answer.
All this depends on a choice you make at first : the choice to extend the logarithm function from $\mathbb R^*_+$ to $\mathbb C$. Any two choices are equal modulo $2i \pi$. In particular, for any $z \in \mathbb C$, there exists $n$ such that $\mathrm{log}(\mathrm{exp} \, z) = z + 2in\pi$.
Here are the details of what fails in your example : $ (x^b)^{\frac{1}{c}} = \mathrm{exp}(\frac{1}{c}\mathrm{log}(e^{b \mathrm{log} \,x}))$, so there exists $n$ such that $\mathrm{log}(e^{b \mathrm{log} \, x}) = b \mathrm{log} \, x + 2in\pi$. Then $(x^b)^{\frac{1}{c}} = x^{\frac{b}{c}} \times \mathrm{exp}(\frac{2in\pi}{c})$.
The conclusion is that the formula works only if $x$ is in $\mathbb R^*_+$.