It happens, so you train for it. The Controlled Emergency Swimming Ascent was intense.
This is a practice of what to do if you run out of air.
You and your instructor ascend to the surface together holding on to a line anchored to the seabed while you exhale (making an “ahh” sound) all the way to the surface. Breathing out protects your lungs from over expanding as you pass through water with less air pressure.
If you ever need to escape a submarine say if you're in the Navy, this is a variation on how you'd do it. More like in the video.