// Code derived from Stroustrup's PPP2 book// § 5.6.3 Bad input// -and beginning on p 150#include<iostream>#include<stdexcept>usingstd::cerr;usingstd::cin;usingstd::cout;usingstd::runtime_error;voiderror(constchar*s){throwruntime_error(s);}doublesome_function(){cout<<"Please enter a float:\n";doubled=0;cin>>d;if(!cin)error("couldn't read a double in 'some_function()'");// do something useful . . .returnd;}intmain()try{doublefunc_res=some_function();cout<<func_res<<'\n';}catch(runtime_error&e){// catch runtime errorscerr<<"Exception: runtime error, "<<e.what()<<'\n';return1;}