Why are constant electric fields considered when their energy is infinite? Sometimes in some problems (that i am facing in high school physics related to electrostatics) like the problems of finding flux crossing through a cube where magnitude of electric field is some constant $K$ and in a particular direction.
Why do we take the electric field to be constant everywhere?
I mean that we all are familiar with the formula of energy stored in electric field to be
$$\int \frac12 \epsilon_0 E^2\, \text dv.$$
That would make the energy stored in this field to be infinite.
But still we are being taught these cases. I have seen other cases like this where the field is proportional to $x$ coordinate, etc.
Now is this a thought that everyone thinks before doing the question, or am I just the fool who keeps on checking about these things in almost all problems?

One thought is that why are we studying these cases is that the electric field is constant for the patch we are observing or there is only slight variation in magnitude of electric field in that patch
 A: Of course constant electric fields are an approximation, which are valid only in very definite regions of space (e. g. inside a capacitor). For example, the case of the electric field of an infinite plane is valid either if one admits the existence of infinite planes or if one says that there is a very big (but finite) plane and that one is looking in places close enough to the plane to negelct "boundary effects". One can thus assume that the field there is constant but this is valid only as long as one stays close enough to the plane!
In then one wants to compute the total energy stored in the field using "your" integral, a more precise version of it would be
$$1/2\epsilon_0\left[ \int_{close\; to\; the\; plane} E^2_{const}\; dx + \int_{rest\; of\; space} E^2_{unknown} dx \right] $$
where we have split the integral in space in two parts: one close to the plane where we assume the fiels is constant and one in the rest of space where we do not know the field. You can however be sure that the total integral will not be infinite, as the one "close to the plane" is in a finite volume (and thus is finite) while the other one will not diverge as the field is not constant anymore, but will decrease as you go away from the source!
Another way to see this is that whatever realistic charge distribution you have (a very big plane, a very big sphere, a very big whatever), if you are far away enough it will still look to you like a point charge so that if the distance from the source $r$ is big enough the field decreases as $\sim 1/r^2$ (the electric field of a point charge) and the integral of the energy converges.
Again, we can write:
$$1/2\epsilon_0\left[ \int_{close\; to\; the\; plane} E^2_{const}\; dx + \int_{rest\; of\; space} E^2_{unknown} dx \right] \approx $$
$$1/2\epsilon_0\left[E^2_{const}V_0 +  \int_{rest\; of\; space} A/r^4 dr \right] <\infty $$
where $V_0<\infty$ is the volume in which the constant field approximation is valid and $A$ is just a constan to get rid of the details. The second integral is not infinite, and the total energy stays finite! (Of course there will be a transient between a constant $E$ and a $E\sim 1/r^2$ situation which I neglected here..!)
So, summing up, the "constant field" approximation is only valid in finite volume (unless you assume infinite charge distributions).
A: Same reason why we say $g=9.8 m/s^2$. It's obviously not constant, but... is it an approximation? Yes. Is that approximation valid? It is... within a certain region
A constant electric field is a mathematical construct. You can study iut mathematically. Then, in physics, you have to know the scope of those calculations.
