Hello all!
How do i check if a result is of the right type(int, float, double, etc.) and then throw and catch an exception in case it's not?
Thanks all,
Vlad.
Hello all!
How do i check if a result is of the right type(int, float, double, etc.) and then throw and catch an exception in case it's not?
Thanks all,
Vlad.
There is no way to know that at runtime with C++. These would be compile-time errors.
To answer your second question, you have to manually check for buffer overflows/underflows or use a more appropriate datatype.
Could you give more detail about what is giving you "a result" you may be able to determine what you need from there and more likely in a better way.
If all you really want is to check the type, use typeid
.
More info here
Following Daniel's model of editing posts to actually answer the question after stating something else...
From my other comment:
You have to do this BEFORE you have just the result. Checking for overflow after is not a good idea. Do a check on the numbers before adding to see if they will overflow, or restrict input to be less than half the max value of the type
Well to make it simple, let's say I have two numbers and after adding them or any other operation the result is bigger or low than the int range. So there any way to throw and catch an exception when the result gets out of bounds?