That's their main use
With a missile coming toward you at Mach 2-3 you don't want to be shooting subsonic cannon shells at it.
The rail gun ammunition is much smaller so you can carry much more of it and make a much more mobile gun turret because it doesn't need to store tonnes of shells or have a feed back to a magazine.