We calculate the effect of an inhomogeneous magnetic field, which is invariably present in an experimental environment, on the exchange energy of a double-quantum-dot artificial molecule, projected to be used as a two-qubit quantum gate in the proposed quantum-dot quantum computer. We use two different theoretical methods to calculate the Hilbert space structure in the presence of the inhomogeneous field: the Heitler-London method, which is carried out analytically, and the molecular orbital method, which is done computationally. Within these approximations we show that the exchange energy J changes slowly when the coupled dots are subject to a magnetic field with a wide range of inhomogeneity, suggesting that swap operations can be performed in such an environment as long as quantum error correction is applied to account for the Zeeman term. We also point out the quantum interference nature of this slow variation in exchange.