WhiskyMHD: A new numerical code for general relativistic magnetohydrodynamics The accurate modelling of astrophysical scenarios involving compact objects and magnetic fields, such as the collapse of rotating magnetized stars to black holes or the phenomenology of γ-ray bursts, requires the solution of the Einstein equations together with those of general-relativistic magnetohydrodynamics. We present a new numerical code developed to solve the full set of general-relativistic magnetohydrodynamics equations in a dynamical and arbitrary spacetime with high-resolution shock-capturing techniques on domains with adaptive mesh refinements. After a discussion of the equations solved and of the techniques employed, we present a series of testbeds carried out to validate the code and assess its accuracy. Such tests range from the solution of relativistic Riemann problems in flat spacetime, over to the stationary accretion onto a Schwarzschild black hole and up to the evolution of oscillating magnetized stars in equilibrium and constructed as consistent solutions of the coupled Einstein-Maxwell equations.