We report on a detailed investigation of terahertz-emission properties related to resonant cavity modes. We discuss data for an underdoped and an optimally doped Bi2Sr2CaCu2O8+x (BSCCO) intrinsic junction stack having the same geometry. At high bias, in the presence of a hot spot, the emission frequency seems to be continuously tunable by changing the bias current and the bath temperature. By contrast, at low bias the emission frequencies f(e) are remarkably discrete and temperature independent for both stacks. The values of f(e) point to the formation of (0, m) cavity modes with m = 3 to 6. The total voltage V across the stack varies much stronger than f(e), and there seems to be an excess voltage indicating groups of junctions that are unlocked. For the case of the underdoped stack we perform intensive numerical simulations based on coupled sine Gordon equations combined with heat-diffusion equations. Many overall features can be reproduced well and point to an unexpected large value of the in-plane resistivity. However, unlike in experiment, in simulations the different resonant modes strongly overlap. The reason for this discrepancy is presently unclear.