Why does the formula for $\tan 3\theta$ work at $\theta=\frac\pi4$ even though its proof involves cancelling $1-\tan^2\theta$? Here's a proof for the $\tan 3\theta$ formula:

According to the procedure for the proof, when we cancel out $1-\tan^2\theta$, the value of $1-\tan^2\theta$ should not be equal to $0$ (in particular, $\theta$ should not be $\frac{\pi}{4}$) as $\frac{ax}{bx}=\frac{a}{b}$ only if $x$ isn't $0$.
But, when we substitute $\theta=\frac{\pi}{4}$ in the final formula, we still get the correct answer:
$$\frac{3\tan\frac{\pi}{4}-\tan^3\frac{\pi}{4}}{1-3\tan^2\frac{\pi}{4}}=\tan\frac{3\pi}{4}=-1$$
How is this possible?
 A: This question has been answered in a comment but an important point to make here is that proving something is true for a smaller set of values does not say anything about whether it is true on a larger set of values.
Consider the theorem "For $m,n\in \mathbb{Z}$, $m+n$ is even if $m$ and $n$ are odd".
Suppose $m=2a+1, n=2b+1$. Then $m+n=2(a+b+1)$ which is even.
This theorem is of course true when both $m$ and $n$ are  even, but the proof is not identical.
EDIT: Also it is slightly overkill to use continuity here. Having $\tan^2 x=1$ be the only problematic value here, we can verify the case $x=\frac{\pi}{4}$ then use identities.
A: You could also first compute the triple angle formulas for sine and cosine,
$$
\sin(3x)=\frac1{2i}(e^{i3x}-e^{-i3x})=\sin(x)(e^{i2x}+1+e^{-i2x})=\sin(x)(-4\sin^2(x)+3)\\
\cos(3x)=\frac12(e^{i3x}+e^{-i3x})=\cos(x)(e^{i2x}-1+e^{-i2x})=\cos(x)(4\cos^2(x)-3)\\
$$
so in consequence
$$
\tan(3x)=\tan x\,\frac{3\cos^2x-\sin^2x}{\cos^2x-3\sin^2x}=\tan x\,\frac{3-\tan^2x}{1-3\tan^2x}
$$
