Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
int divide(int a, int b);
int divide(int a, int b)
{
if (b==0) throw DivisionByZeroError
return a/b;
}
int divide(int a, int b)
{
ASSERT(b!=0);
return a/b;
}
typedef std::pair<bool,int> DivideResult;
// Division ok : the bool == true and the int == a/b
// Division failed: the bool == false and the int == 0.
DivideResult divide(int a, int b)
{
if (b==0)
return DivideResult(false,0)
else
return DivideResult(true, a/b);
}
{
...
DivideResult r = divide(foo,bar);
if (r.first)
{
// Division ok
result = r.second;
}
else
{
// Division failed
...
}
}
if (divide(a,b)+divide(c,d) == 42) { .... }
int divide(int a, int b)
{
if (b==0) throw DivisionByZeroError
return a/b;
}
DivideResult attemptDivide(int a, int b)
{
try
{
return DivideResult(true, divide(a,b));
}
catch (DivisionByZeroError&)
{
return DivideResult(false, 0);
}
}