fork(2) download
  1. #include <iostream>
  2. #include <exception>
  3.  
  4. class BadUrl:public std::exception
  5. {
  6. const char* what() const noexcept {return "url is not correct!\n";}
  7. };
  8.  
  9. struct Page
  10. {
  11. std::string data;
  12. };
  13.  
  14. Page download(const std::string& address)
  15. {
  16. if(address.size()==0)
  17. throw BadUrl();
  18.  
  19. Page page;
  20. page.data="blah blah...";
  21. return page;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27. try{//code haye dakhele in block check mishan
  28. download("");
  29. }
  30. //khat zir exception hayee ke az class std::exception ers bordan ro migire
  31. catch(std::exception& exc){
  32. std::cout<< exc.what();//url is not correct chap mishe
  33. }
  34. //dar soorat bargardoondan exception ee
  35. //ke az std::exception ers naborde bashe
  36. //khat zir ejra mishe
  37. catch(...){
  38. std::cout<<"undefined error...";
  39. }
  40.  
  41. }
  42.  
  43.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
url is not correct!