Since invaders flee when about half of them have been neutralized, capturing all of them would require you to get them to path into an are you can block off before the first ones start to get caught/killed in large numbers. If you were to use that kind of tactic, you should have a (cage) trapped exit you open to let the routed enemy "flee". I'd say that's too much work: just capture those you can and leave the rest for the next siege (they'll usually come back, but you can deplete their home "town", and a civ only sends sieges from a single location, and doesn't know how to recruit from others).
Undead used to just mill about aimlessly, with the occasional case of actually trying to move to the fortress. The situation may have improved, but I haven't had enough sieges yet to say that definitely. The recent "introduction" of bugged hello/goodbye sieges where a siege is announced and then disappear, or almost disappear, immediately is also an issue. In the latter case the stragglers tend to just sit by the edge unless something the can attack comes in range. It's also possible for a few (up to 5 in my experience) additional troops to jump in from off the map if these stragglers are attacked.
I've never had a war with either elves or humans. In rare cases you can be at war with these races on embark, and you can provoke war with them with a sustained effort.
I catch everything using cage traps. Large number of cage traps... The default parameters for maximum sieges is something like 120 troops, the same number of mounts, and 40 trolls/ogres. These parameter can be changed to allow for larger or smaller sieges. Note that this is the maximum: there's nothing guaranteeing they'll be that size. In fact, the first gobbo siege tends to be 10 poorly equipped gobbos. Also, the attacking settlement can be small, and thus only have a small number of troops available. The next siege can occur the season after the last one. You also need a "processing plan" for your captives, or a mighty large "animal" stockpile with an even larger supply of cages.
Undead can attack at any time: I've had them visit at the start of the first summer, so my very first defense is a door I can lock.
Necros are a bit tricky to catch, because they generally sneak and flee as soon as they're detected. If you don't have anything guarding your outer entrance(s) they frequently get caught in cage traps while sneaking, though. However, not having any outer detection means weres will not be detected until they're upon you, which means they'll probably start a blood bath.
Caged enemies do not succumb to hunger/thirst: I've had "goblin" invaders of the elven, human, and dwarven kind that didn't thirst despite being caged for years.
Again, to catch as much as possible, have a long, winding path so they can all get in, close the exit, wait for the front to get caught in the inside massive array of cages, open the escape exit filled with massive numbers of cages. You'll probably want something like 280 cages on each side in that setup...
I use three entrances, a wide trade one and 2 single tile ones. I try to fit as many traps as I can in these entrances (the trade one has a serpentine patch around cage trap lines), but I tend not to get ready with everything before the first siege (undead + I've set the goblin attack threshold to a pop of 20 rather than the default of 80). I then use a divide and conquer handling of the siege: I let a number of them in through the first entrance they target, close it off as the cages start to get full, clear out those cages and reload the traps, meanwhile the enemy tries another entrance... Continue until they break and rout.