#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <exception>
using namespace std;
/*
try , catch , throw
try
{
....
cod vulnerabil
....
}
catch( tip_date )
{
....
}
catch( tip_date )
{
....
}
catch( tip_date )
{
....
}
catch( tip_date )
{
....
}
*/
void f()
{
cout<<" f() "<<endl;
throw 123;
}
class abc
{
public:
abc(){ throw 777.888; }
};
class ERR : public exception
{
public:
char* what() const throw(){ return "Mesaj de eroare"; }
}XXX;
int main()
{
srand(time(0));
try
{
throw XXX;
}
catch(exception &e)
{
cout<<" ERR Eroare :: "<<e.what()<<endl;
}
/*
try
{
int *p = new int[99999999999];
cout<<" Sa alocat cu succes"<<endl;
}
catch(bad_alloc &e)
{
cout<<" bad_alloc Eroare :: "<<e.what()<<endl;
}
catch(exception &e)
{
cout<<" exception Eroare :: "<<e.what()<<endl;
}
catch(...)
{
cout<<" exception Eroare "<<endl;
}
*/
/*
char sir[256]="step";
string S="itSTEP";
try
{
// cod
int x;
x=3;
throw 123;
if( x == 7 ) throw S;
if( x == 6 ) throw sir;
if( x == 5 ) throw "Eroare";
if( x == 4 ) throw 'a';
if( x == 3 ) throw 3.14;
if( x == 2 ) throw 123;
if( x < 2 ) throw true;
// cod
}
catch(bool e)
{
cout<<" Exceptie bool = "<<e<<endl;
}
catch(int e)
{
cout<<" Exceptie int = "<<e<<endl;
}
catch(double e)
{
cout<<" Exceptie double = "<<e<<endl;
}
catch(char e)
{
cout<<" Exceptie char = "<<e<<endl;
}
catch(char e[])
{
cout<<" Exceptie char[] = "<<e<<endl;
}
catch(const char e[])
{
cout<<" Epxceptie const char[] = "<<e<<endl;
}
catch(string e)
{
cout<<" Epxceptie string = "<<e<<endl;
}
catch(...)
{
cout<<" Epxceptie ... "<<endl;
}
*/
/*
int a,b, i=0;
while( i < 10 )
{
try
{
a=rand()%5;
b=rand()%5;
if( b == 0 ) throw " Eroare impartirea la ZERO";
cout<<i<<" a="<<a<<" b="<<b<<" a/b= "<<a/b<<endl;
}
catch( const char e[])
{
cout<<i<<" xxx a="<<a<<" b="<<b<<" a/b= "<<e<<endl;
}
catch(const char[])
{
b=rand()%10+10;
cout<<i<<" xxx a="<<a<<" b="<<b<<" a/b= "<<(double)a/b<<endl;
}
catch(...)
{
cout<<" Erorare "<<endl;
}
i++;
}
*/
/*
try
{
f();
}
catch(double e)
{
cout<<" double f() = "<<e<<endl;
}
catch(int e)
{
cout<<" int f() = "<<e<<endl;
}
*/
/*
try
{
abc A;
}
catch(double e)
{
cout<<" double abc OBJECT = "<<e<<endl;
}
catch(int e)
{
cout<<" int abc OBJECT = "<<e<<endl;
}
*/
// sqrt X de n ori X => cu valor random -10 ... 10
return 0;
}