I had a lot of trouble doing this problem on my exam. Can anybody please tell me why my attempt fails?
Let $X$~$Uniform(0,1)$ and $Y$~$Uniform(0,1)$ be independent random variables. Find the density of $Z = XY.$
Solution attempt: For $a\in(0,1):$ $F_Z(a) = P(Z<a) = P(XY < a) = P(Y < \frac{a}X) = \int_0^1\int_0^{\frac{a}x}f_X(x)f_Y(y)dydx = \int_0^1\int_0^{\frac{a}x}1dydx = \int_0^1(\frac{a}x)dx = (aln|x|)\rvert_0^1 = aln(1) - aln(0) = -aln(0)$ which is undefined..

You forgot the condition $\frac a x <1$ when you wrote the integral from $0$ to $\frac a x$. It should be $$\int_0^1\int_0^{\min\{1,a/x\}}1\,\mathrm d y\,\mathrm d x ~=~ \int_a^1\int_0^{\frac{a}x}1\,\mathrm d y\,\mathrm d x+ \int_0^a\int_0^{1}1\,\mathrm d y\,\mathrm d x$$