It IS possible to wall off cavern, though. When done (correctly), a cavern is completely safe (well, as safe as any part of a fortress).
The way I do it:
- When the cavern is breached (by digging up/down stairs), plug the breach immediately by building an Up (only) stair two levels above the breach (for some reason it can't be built at the breaching level). Dorfs can build this Up stair standing on the building tile.
- Prepare for cavern entry by building an airlock with a bait door and a number of cage traps in it. An "airlock" is a space between two raising drawbridges, each controlled by a lever. The outer one (closer to the cavern) should be one tile away from the cavern so a miner has to remove a single tile to open up the passage. The door can be locked to delay critters trying to enter sufficiently long for the drawbridge levers to be pulled (and it's a good idea to test that the drawbridges and levers are constructed correctly before opening up the cavern access...).
- Wait until the critters visible are of a reasonable benign type (such as elk birds or rutherers). Station your militia (which in my case typically is the dorf who was assigned the spare embark axe, with no training or other equipment) by your airlock and designate the access tile to be mined away (I give it priority 1 to get it done reasonably promptly). Once the access is free (or before that, actually), make a burrow that covers the whole embark except the cavern you're breaching and set it as a civilian alert burrow which you activate. This stops every dorf and his uncle from rushing into the cavern to haul those EXTREMELY VALUABLE old bones to the refuse and corpse stockpiles. Move your militia around the cavern by setting up new stations as more of the cavern is revealed. This way you should be able to explore it. Withdraw if you see nasties, or when the cavern has been explored. Station your militia inside of the airlock and close the outer drawbridge.
- Wait (it may take years if the timing is bad) until you get a new batch of benign critters entering the cavern. As you've explored it, you'll see everything in it (except Gremlins, but they're rare and not particularly dangerous). The latest critter to enter the embark is listed at the top of the Units/Other screen, so by checking that screen you can see when a fresh group has entered.
- Once you finally have a benign group in the cavern, open up the cavern (no civ alert [and you did remove the old one when done, right]), send your wood cutter(s) to cut trees in the cavern, with priority to clear the edges (so you can build there). Select a number of sections along the edge for an "exterior" (I use 4 of those, one on each side) where you build a wall one tile in from the edge so a single tile space exists between the wall and the outside. Any critters entering there will be stuck there and stay around until they leave (except FBs, which stay until killed by other FBs). These walls are built from the wood of the trees cut, and I typically select as long a stretch as possible that's as low as possible. If the stretch is higher than a single Z level, build a ramp to allow you to get up on top of the wall to build a wall above the gap created (i.e. flush with the edge), and if it's more than two Z levels, build Up stairs on top of the lower wall to reach higher (I try to space those 3 tiles apart). Build Up/Down stairs on top of the Up stairs and continue until you reach the roof, and build your wall, level by level (I assume you know how to build high walls).
I don't actually do exactly this, but build "outer" drawbridges in preparation for airlocks to those sections (don't forget to place an Up stair above the bridge to plug the hole if more than two Z levels, and a floor if 2).
- You'll typically can't build a complete section before the critter group leaves, so once it's due to leave (I use the groups for the other caverns and the surface as estimates of when it's due), activate the cavern civ alert to withdraw your builders and wood cutters, raise the outer airlock drawbridge, and wait for a new building opportunity.
- Once your first section is done, there's a chance an entering group enters on the outside of the section, and if so, it's reasonably safe to file out into the cavern to continue working ("reasonably safe", because FBs can arrive at any time, and savage biomes allows for two concurrent groups). Once all sections are done, there's a good chance entering critters end up in one of those, allowing you to work on the next phase, which is to cover up the rest of the edge. Build walls flush with the edge (on every Z level), until the whole edge is covered by walls or exterior spaces (typically over multiple sessions). Once done, everything is "inside".
- If there are cavern lakes that extend to the edge. magma has to be used to obsidianize them, which is a pain, but possible. Trees in cavern lakes can be removed by firing ballista bolts at them.