Best practice is either
Use reasonable types in your system. Keep in mind that an int machine is not a mathematical integer. If your program might need to use numbers from the machine int range, you should use a large integer library, not machine ints.
Defend the defense. If the operation can cause the value to fall outside the range, then you should explicitly check it after the operation is complete (or, even better, check it before the operation to see if the arguments lead to an error).
Of course, if you do 2., you still need to decide what to do if an error occurs, and you are not from 1. However, using large integers will result in poor performance in most languages. Regardless of whether this runtime is more or less than the fine from performing security checks, it will probably depend on the programming language and the features of your program.
In the end, the task of the programmer must be responsible for the code that they write. Language can only provide you with such help.
source share