Advertisement
wilk_maciej

obsluga_wyjatkow

Jun 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. double function1 (double x, double y){
  8.   if (y==0){
  9.     string wyjatek="Dzielenie przez zero! ";
  10.     throw wyjatek;
  11.   }
  12.   return x/y;
  13.  
  14. };
  15.  
  16. double function2(void){
  17.   try{
  18.     std::cout <<"Sprawdzam wyjatek dzielenia przez zero:" <<endl;
  19.     function1(4,0);
  20.   }catch(string o1){
  21.     cout <<"Wyjatek: " <<o1;
  22.   }
  23.   return -1;
  24. };
  25.  
  26. int main(){
  27.   double x=function1(5,3);
  28.   cout <<x <<endl;
  29.   double y=function2();
  30.   cout <<y <<endl;
  31.   double z=function1(7,7);
  32.   cout <<z <<endl;
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement