Here is a link on
c++ exception handling[
^]
Overflow, Zerodivide and CannotMakePositive are C++ classes, and in this case they are used to convey information about error conditions in the form of exceptions.
A simplistic explaination is that
throw
breaks off the normal execution flow. Execution will continue inside the closest
catch
block for the closest match for the thrown type.
long long t = (long long)b.val * (long long)a.val;
The result of an integer multiplication may owerflow - the result could be larger than what fits inside a 4 byte integer. So the code uses
long long
, 8 byte integers. the result of multiplying two 4 byte integers will allways fit inside an 8 byte integer. The code then checks that the result is inside the valid range for a 4 byte int, and if it's not throws an instance of an
Overflow
object created using
Overflow();
.
On
return t
the compiler looks for a way to convert the
long long t
to a
INt
using the best matching constructor for
INt
matching with
INt(int i): val(i) {}
. You should see a warning though ...
Regards
Espen Harlinn