#include <iostream>
class X{
int val;
public:
X(int v){
std::cout<<"Constructor with value: "<<v<<"\n";
// no try - catch
if(v<0){
std::cout<<"Invalid "<<v<<"\n";
throw 505; // exception code
}
std::cout<<"OK "<<v<<"\n";
this->val = v;
}
~X(){
std::cout<<"Destructor with value: "<<this->val<<"\n";
}
};
int main()
{
X *a, *b, *c;
// try - catch
try{
a = new X(900);
b = new X(0);
c = new X(-999);
}catch(int e){
std::cout<<"Catch with exception code: "<<e<<"\n";
}
delete c; // no effect
delete a;
delete b;
return 0;
}