Thursday, June 25, 2009

The exception structure has been added



NOTE : -
THIS CONTENT IS NOT ORIGINAL

11. The exception structure has been added

You know the classical control structures of C: for, if, do, while, switch... C++ adds one more control structure named EXCEPTION:


using namespace std;
#include
#include

int main ()
{
int a, b;

cout << "Type a number: ";
cin >> a;
cout << endl;

try
{
if (a > 100) throw 100;
if (a < 10) throw 10;
throw a / 3;
}
catch (int result)
{
cout << "Result is: " << result << endl;
b = result + 1;
}

cout << "b contains: " << b << endl;

cout << endl;

// another example of exception use:

char zero [] = "zero";
char pair [] = "pair";
char notprime [] = "not prime";
char prime [] = "prime";

try
{
if (a == 0) throw zero;
if ((a / 2) * 2 == a) throw pair;
for (int i = 3; i <= sqrt (a); i++)
{
if ((a / i) * i == a) throw notprime;
}
throw prime;
}
catch (char *conclusion)
{
cout << "The number you typed is "<< conclusion << endl;
}

cout << endl;

return 0;
}


Output
Type a number: 5

Result is: 10
b contains: 11

The number you typed is prime





BIBILOGRAPHY / REFERENCE : - http://www.4p8.com/eric.brasseur/cppcen.html

No comments:

3G S

JAIL BREAK

iPHONE

BILL GATES

StEvE JoBs

steve jobs

STEVE JOBS

Steve Jobs

Love Country

SD

Burroughs

Lift

Joseph Johnson

Apple Rainbow

Apple Blue

Apple Laser Printer