#include <string> // for string
#include <stdexcept> // for exception, runtime_error, out_of_range
#include <iostream> // for cout
using namespace std;
int area(int length, int width){
if(length<=0 || width<=0){
throw runtime_error("Non positive area length="+to_string(length)+" width="+to_string(width));
}
return length*width;
}
int framed_area(int x, int y){
return area(x-2,y-2);
}
int main() {
int x=-1;
int y=2;
int z=4;
try{
int area1=area(x,y);
int area2=framed_area(1,z);
int area3=framed_area(y,z);
double ratio=double(area1)/area3;// double division!
}
catch(runtime_error & e){
cout<<e.what();
}
return 0;
}