You're likely referring to the secret door in Bilbo Baggins's hobbit-hole in J.R.R. Tolkien's The Hobbit. There wasn't actually a way out while the secret door was closed; it was designed to be locked from the inside to keep unwanted guests out. However, other exits existed:
The "only way out" depends on the specific circumstances. Let me know if you'd like to explore any of these options further.