Brakes use friction to slow you down. Rim brakes use the friction between the rubber brake pad and the aluminum rim. While the rubber is usually the component that wears away, if the pad picks up sharp grit (from muddy rides, or from commuting), this grit can become embedded in the pad and can grind through the rim.
Check your pads and rims regularly – if the braking surface of the rim has uneven lines worn into it, or feels concave to the touch, then your rim is beginning to wear. If you have little stress cracks forming on or near the braking surface and parallel to the rim, then you need to change out the rim immediately.
Rims give up at odd times, like when you are just riding along, or when the bike is sitting on your car after a ride. The pressure of the tube and tire against the rim makes the failure relatively explosive – even if the tube doesn’t burst, the tire bead will pop off with a noise not unlike a gunshot.
There isn’t much hope for the rim once it has broken in this way. A tire will not stay on it easily, and the rim itself cannot be repaired. You can attempt to stuff the tire with pine cones or similar, and zip tie it on to the rim – but that involves removing the brake arms and will damage the tire. Instead, remove the tube and tire, and ride on the rim. Ride slowly and carefully, dismounting for any rough sections, and the remains of the rim should see you home.
Tip: Regularly clean rims and brake pads on rim brake bikes. Use a green “Scotchbrite” scouring pad and dishwashing detergent. This will remove the dirt which causes premature wear and will also improve your braking.