  Electric currents play an important role in the energy balance of the plasma
in the solar atmosphere. They are also indicative of non-potential magnetic
fields and magnetic reconnection. Unfortunately, the direct measuring of
electric currents has traditionally been riddled with inaccuracies. We study
how accurately we can infer electric currents under different scenarios. We
carry out increasingly complex inversions of the radiative transfer equation
for polarized light applied to Stokes profiles synthesized from radiative
three-dimensional magnetohydrodynamic (MHD) simulations. The inversion yields
the magnetic field vector, ${\bf B}$, from which the electric current density,
${\bf j}$, is derived by applying Ampere's law. We find that the retrieval of
the electric current density is only slightly affected by photon noise or
spectral resolution. However, the retrieval steadily improves as the Stokes
inversion becomes increasingly elaborated. In the least complex case (a
Milne-Eddington-like inversion applied to a single spectral region), it is
possible to determine the individual components of the electric current density
($j_{\rm x}$, $j_{\rm y}$, $j_{\rm z}$) with an accuracy of $\sigma=0.90-1.00$
dex, whereas the modulus ($\|{\bf j}\|$) can only be determined with
$\sigma=0.75$ dex. In the most complicated case (with multiple spectral
regions, a large number of nodes, Tikhonov vertical regularization, and
magnetohydrostatic equilibrium), these numbers improve to $\sigma=0.70-0.75$
dex for the individual components and $\sigma=0.5$ dex for the modulus.
Moreover, in regions where the magnetic field is above 300 gauss, $\|{\bf j}\|$
can be inferred with an accuracy of $\sigma=0.3$ dex. In general, the $x$ and
$y$ components of the electric current density are retrieved slightly better
than the $z$ component.
