I'd suggest reading the "accidents & incidents" forum for plenty of good learning material.
But to respond directly: I was on a boat dive recently. I geared up, and did my usual gear check. The last thing I do before I get in the water, is check to make sure I have air in my tank, and then I take a breath or two from my reg to make sure it's working properly. I did my backwards roll, gave the boat my "ok" signal, and grabbed my camera from the mate. I swam around the stern, and started working my way down. At about 4 feet, my reg locked up. I switched to my octo/inflator, and it was locked up too. Luckily I was close to the surface, so I swam up (remembering to exhale tiny bubbles) and broke the surface. I signaled to the mate, and told him my reg was locked. I could see the look of confusion on his face as I told him my back-up reg was frozen too. He had just checked my valve, and watched me check my spg, and take breaths off my reg. I got to the back of the boat , and he checked my valve again. It was turned off. The best we can figure, is that while moving around the back of the boat, and down the line, a rope somehow rolled my tank valve back far enough to cut off my gas. I'm just lucky I was so close to the surface.
I've also had buddies with reg or octopus issues leaking gas or free-flowing. 99% of the time it's been fixed by tapping the purge button a time or two (probably cause by sand in the reg). I had a hp hose crack on me, but I caught that during my gear check. It split under the hose protector, so the crack was not visible, but the leak was just loud enough for me to hear. (guess that didn't really happen underwater though) Had a mask completely flood in heavy current on a night dive. That was a big p.i.t.a. but my buddy noticed I was having issues, and stood by while I got the problem fixed.
Gear problems are going to happen. I do my best to learn from them, and hopefully they will make me a better diver in the long run.