There's a bunch of reasons that gas might become unavailable during a dive. Some are rare and unpredictable, some are equipment related, others are simple human error. Most are avoidable.
The cause for gas delivery cessation has an impact on whether any 'symptoms' might be recognizable. In some cases you might get a progressively harder work of breathing, in others the cessation is abrupt and final.
Whatever the cause, and whatever the warning, the situation; and response, remains simple. Seek an alternative supply of breathing gas. That may be from a redundant gas source, a buddy or at the surface. You, the diver, determines which alternative source is available to you...
Probably the most common cause of OOG emergency is absolutely human error; you breath the cylinder down until no gas remains deliverable through the regulator. This occurs due to insufficient situational awareness.
Appropriate situational awareness (
gas, time, depth, buddy, location, conditions, hazards) is a product of maintaining a conservative bias towards reduced dive challenge/complexity over your experience and capability. Task loading and stress degrade situational awareness. Task loading reduces with experience; and this even includes specific experience in the equipment you are using in a given dive.
Surprisingly,

even the most basic entry-level diving courses provide very astute advice on how to maximize your situational awareness - basically, take it easy and dive well within your comfort zone; inside the limits of your training and experience.
That advice remains prudent no matter to what levels of technicality that your diving progresses.
Negligently running out of breathing gas underwater remains, and shall always be, the most quintessential expression of Darwin's Law provided by the scuba community....