C ++ assumes that you know what you are doing, don’t pay for what you don’t ask for, and don’t make any assumptions about the platforms for which it was intended.
If you want to divide the numbers, it would be very inefficient to ask the compiler to check the denominator and throw before division. (We did not ask for this.) So this option is missing; we cannot have this check on every division, and this is especially wasteful, since most divisions are not zero.
So, how can we just divide by zero and find out if this works? Since C ++ cannot accept something regarding this platform, it cannot assume that there is a way to check the result, in hardware. In other words, while many processors will switch to some kind of interrupt when division by zero occurs, C ++ cannot guarantee such a thing.
The only option is that the behavior should be undefined. And this is exactly what you get: undefined behavior.
OOP languages ​​can do something, it does not matter, since OOP is not well-defined, and C ++ is not an OOP language. In general, use the most suitable tool. (Exceptions for exceptional situations.)
GManNickG
source share