Oh yes, if only everything could be perfect. My belief is that, if you are talking houses, the word "perfect" never applies. That is my view, having worked for several years as a home inspector in Bellingham.
Here is an example -- I often find water heaters that are installed in finished living space and the tank has no pan with a drain to the outside underneath it. The inspection report language goes much like this:
The water heater is installed over finished living space and has no catch pan and drain installed. While the probability of this becoming an issue increases proportionally with the age of a water heater, should the tank develop a leak, a pan and drain will route any water outdoors so interior damage would be minimized. Recommend that client consider having a pan with a drain installed by a qualified party, such as a plumber. For an illustration of a typical pan and drain, see the illustration below:

That photo, of the model tank, shows a great water heater installation. But, in older homes and many condos or houses with basements, the water heaters we find in finished areas, more often than not, have no pans or drains.

It is not always easy to figure out a way to get around this problem. Obviously, if a person is buying a condo, the association is not going to take kindly to the new residents running pipes through shared areas. And a tank in a finished basement may be too low for gravity to be effective. The pan would not drain.
Rejoice, there is a decent option.
Install a pan under the tank. Make sure the pan is big enough that it will accommodate an inexpensive water leak alarm. The device is inexpensive and the alarm will sound even if small quantities of water are detected. Now, these devices require new batteries each year -- remember to put in a new battery on Christmas day or your birthday. Of course, if you are not around to hear the alarm if it goes off, then that is a problem too.

These affordable units are available at any number of Online and hardware stores.
If we are rating ways to thwart the dreaded water heater leak, I think the best remedy is tried and true -- a pan and drain to the outside.
Second best would be a pan under the tank with a water leak detector inside the pan.
And, last of all -- not as good as the others but better than nothing -- would be simply putting a water leak detector on the floor beside the water heater. It would sound if there was even a small leak so, hopefully, major interior damage could be avoided. If you are away from home when a leak occurs, all bets are off.
If you wish to spend some money, to get around this one, a plumber can sometimes install a WAGS valve which is designed to stop the flow of water if there is a leak at the tank. You can google the term "WAGS valve" for more information. It is an imperfect world, sometimes second or third best is as good as it gets!
This is great advice for home buyers it will certainly save a lot of problems if a leak were to happen. Thanks for sharing this information.