Advertisement
Guest User

Untitled

a guest
May 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 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 "Library3.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
  65.     {
  66.         bool c=1;
  67.         throw c;
  68.     }
  69. }
  70. ---------------------------------------------------------------------------------
  71. #include "Library3.h"
  72.  
  73.  
  74. int main(int argc, char* argv[])
  75. {
  76.     Klasa a(3);
  77.     try
  78.     {
  79.         a.Metoda();
  80.     }
  81.     catch(Wyjatek c)
  82.     {
  83.         //printf("%s\n",b.what());
  84.         printf("zlapalem wyjatek o nazwie -");// %s\n",Except->nazwa);
  85.         //printf("%d\n",Except);
  86.     }
  87.     catch(int x)
  88.     {
  89.         printf("zlapalem int'a\n");
  90.     }
  91.     catch(char y)
  92.     {
  93.         printf("zlapalem char'a\n");
  94.     }
  95.     catch(bool z)
  96.     {
  97.         printf("zlapalem bool'a\n");
  98.     }
  99.     system("pause");
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement