Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <exception>
- using namespace std;
- class Klasa
- {
- public:
- int wartosc;
- Klasa(int val=0);
- void Metoda();
- };
- class Wyjatek : public exception
- {
- public:
- int value;
- char* nazwa;
- Wyjatek(int val,char* name);
- ~Wyjatek();
- };
- ------------------------------------------------------------------------------
- #include "Library3.h"
- Wyjatek::Wyjatek(int val=0,char* name="Exception")
- {
- this->value=val;
- this->nazwa=name;
- printf("Jestem konstruktorem wyjatku %s\n",this->nazwa);
- }
- Wyjatek::~Wyjatek()
- {
- printf("Jestem destruktorem wyjatku %s\n",this->nazwa);
- }
- Klasa::Klasa(int val)
- {
- this->wartosc=val;
- }
- void Klasa::Metoda() throw(int,char,bool,Wyjatek)
- {
- if(this->wartosc==0)
- {
- Wyjatek exception(1,"Zero");
- throw exception;
- }
- else if(this->wartosc==1)
- {
- int a=2;
- throw a;
- }
- else if(this->wartosc==2)
- {
- char b='a';
- throw b;
- }
- else
- {
- bool c=1;
- throw c;
- }
- }
- ---------------------------------------------------------------------------------
- #include "Library3.h"
- int main(int argc, char* argv[])
- {
- Klasa a(3);
- try
- {
- a.Metoda();
- }
- catch(Wyjatek c)
- {
- //printf("%s\n",b.what());
- printf("zlapalem wyjatek o nazwie -");// %s\n",Except->nazwa);
- //printf("%d\n",Except);
- }
- catch(int x)
- {
- printf("zlapalem int'a\n");
- }
- catch(char y)
- {
- printf("zlapalem char'a\n");
- }
- catch(bool z)
- {
- printf("zlapalem bool'a\n");
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement