A capital starship could be hardened against EM attack by hardening it literally; just add more mass.
Taking your examples, I am assuming you are not including EM of sufficient power and focus to be used as a gun for destroying your ship outright (ie: high powered laser to blast through your hull), but rather for jamming, overloading via EMP, etc..
Just put enough mass on the outer portions of your ship and it will block practically all of the energy. It could be something like lead, but it could also just be water. And it does not have to be the outermost part of the ship either; it just needs to outside of where the delicate things needing protection are. You could surround only specific compartments if you wanted to: the bridge, datacenter, and a few other things.
Attenuation is the reduction in intensity of the light beam (or signal) with respect to distance travelled through a transmission medium.
The beauty of this is that it absorbs a broad frequency spectrum. If my understanding of faraday cages is correct, they will have a much shorter spectrum over which they work.
What you need to do is decide which EM frequencies are likely used in your scenario then check to see how far they penetrate into various substances. The penetration if deep enough (not blocked trivially) may be measured in some "half-distance" (analogous to radiation half-life) type of unit, generally attenuation coefficient.
So if a certain EM frequency you are worried about has a half-distance of 1 meter in water (based on its attenuation coefficient for that EM frequency), then 1 meter of water will block out about half of it, 2 meters will block 75%, 4 meters 87.5%, and so on. So you put your bridge in the middle of your water reserve so that you have 15 meters of water surrounding you and you block 95% of the energy.
At that point, if a few percent of the energy at some frequency left over is still a concern, you use some other method to absorb, reflect, or otherwise deal with the remaining bit. Such as the faraday cage mentioned by @cypher designed for the frequencies you are worried about that are still getting through a little bit.