// Code derived from Stroustrup's PPP2 book// § 5.10.1 Post-conditions// -and beginning on p 165#include<iostream>#include<stdexcept>usingstd::cerr;usingstd::cout;usingstd::exception;usingstd::runtime_error;voiderror(constchar*s){throwruntime_error(s);}// class Bad_area {}; // a type specifically for reporting errors from area()/*// calculate area of a rectangle;// throw a Bad_area exception in case of a bad argumentint area(int length, int width) { if (length <= 0 || width <= 0) throw Bad_area{}; return length * width;}*/// calculate area of a rectangle;// pre-conditions: length and width are positive// post-condition: returns a positive value that is the areaintarea(intlength,intwidth){if(length<=0||width<=0)error("area() pre-condition");inta=length*width;if(a<=0)error("area() post-condition");returna;}// calculate area within frameintframed_area(intx,inty){constexprintframe_width=2;returnarea(x-frame_width,y-frame_width);}intmain()try{intx=-1;inty=2;intz=4;// . . .intarea1=area(x,y);intarea2=framed_area(1,z);intarea3=framed_area(y,z);doubleratio=area1/area3;cout<<area1<<'\n'//<<area2<<'\n'//<<area3<<'\n'//<<ratio<<'\n';}catch(exception&e){cerr<<"error: "<<e.what()<<'\n';// keep_window_open();return1;}catch(...){cerr<<"Oops: unknown exception!\n";// keep_window_open();return2;}