Professional Documents
Culture Documents
#include<iostream>
int main()
int height;
try
return 0;
PROGRAM 2
#include<iostream>
if (cm == 100)
return cm/2.54;
int main()
int height;
try
return 0;
}
PROGRAM 3
#include<iostream>
if (cm == 100)
return cm/2.54;
int main()
int height;
try
throw 0;
catch (int i)
cout << "Bad input: height cannot be less than " << i << endl;
{
cout << "Exception occured: "<< msg << endl;
PROGRAM 4
#include<iostream>
int main()
int input;
cin >>input;
try
if (input == 2) throw 2;
if (input == 4) throw s;
catch (double i)
catch (int i)
catch(string s)
}
PROGRAM 5
#include<iostream>
if (cm == 100)
return cm/2.54;
int main()
int height;
try
try
throw err;
throw height;
cout << "Person is " << ToInches(height) << " inches tall" << endl;
catch (int i)
cout << "Exception occured: Height must be greater than "<<i<< endl;
PROGRAM 6
#include <iostream>
//#include <exception>
public:
};
int main()
try
int a, b;
// compute a / b
if (b == 0)
Divide_By_Zero_Exception d;
throw d;
else
catch(exception& e)
PROGRAM 7
#include <iostream>
#include <exception>
public:
};
int main()
{
try
int a[10],i;
for(i=0;i<=100;i++)
/* if (i>9)
{*/
Array_bound_Exception d;
throw d;
//}
cin >>a[i];
for(i=0;i<=9;i++)
cout<<a[i]<<endl;
catch(exception& e)
PROGRAM 8
#include <iostream>
};
void my_terminate() {
};
struct A {
~A() {
};
struct B {
};
int main() {
set_terminate(my_terminate);
try {
A a;
cout<<"Inside A"<<endl;
B b;
catch (...) {