Advertisement
Guest User

Untitled

a guest
May 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <exception>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. class Klasa
  9. {
  10. public:
  11.     int wartosc;
  12.  
  13.     Klasa(int val=0);
  14.     void Metoda();
  15. };
  16.  
  17. class Wyjatek : public exception
  18. {
  19. public:
  20.     int value;
  21.     char* nazwa;
  22.  
  23.     Wyjatek(int val,char* name);
  24.     ~Wyjatek();
  25.  
  26. };
  27. ---------------------------------------------------------------
  28. #include "Library4.h"
  29.  
  30. Wyjatek::Wyjatek(int val=0,char* name="Exception")
  31. {
  32.     this->value=val;
  33.     this->nazwa=name;
  34.     printf("Jestem konstruktorem wyjatku %s\n",this->nazwa);
  35. }
  36.  
  37. Wyjatek::~Wyjatek()
  38. {
  39.     printf("Jestem destruktorem wyjatku %s\n",this->nazwa);
  40. }
  41.  
  42. Klasa::Klasa(int val)
  43. {
  44.     this->wartosc=val;
  45. }
  46.  
  47. void Klasa::Metoda() throw(int,char,bool,Wyjatek)
  48. {
  49.     if(this->wartosc==0)
  50.     {
  51.         Wyjatek exception(1,"Zero");
  52.         throw exception;
  53.     }
  54.     else if(this->wartosc==1)
  55.     {
  56.         int a=2;
  57.         throw a;
  58.     }
  59.     else if(this->wartosc==2)
  60.     {
  61.         char b='a';
  62.         throw b;
  63.     }
  64.     else if(this->wartosc==3)
  65.     {
  66.         bool c=1;
  67.         throw c;
  68.     }
  69.     else
  70.     {
  71.         double z=2.2;
  72.         throw z;
  73.     }
  74. }
  75. -------------------------------------------------------------------
  76. #include "Library4.h"
  77.  
  78.  
  79. int main(int argc, char* argv[])
  80. {
  81.     Klasa a(3);
  82.     try
  83.     {
  84.         a.Metoda();
  85.     }
  86.     catch(Wyjatek c)
  87.     {
  88.         //printf("%s\n",b.what());
  89.         printf("zlapalem wyjatek o nazwie -");// %s\n",Except->nazwa);
  90.         //printf("%d\n",Except);
  91.     }
  92.     catch(int x)
  93.     {
  94.         printf("zlapalem int'a\n");
  95.     }
  96.     catch(char y)
  97.     {
  98.         printf("zlapalem char'a\n");
  99.     }
  100.     catch(bool z)
  101.     {
  102.         printf("zlapalem bool'a\n");
  103.     }
  104.     catch(unexpected_handler x)
  105.     {
  106.         printf("problem\n");
  107.     }
  108.    
  109.     system("pause");
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement