Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

Advertisements


website counter



C ++ Concept-Exception Handling


Posted Date: 12 Jun 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: Girish Patil       Member Level: Diamond
Rating:     Points: 3



EXCEPTION HANDLING

The two most common types of bugs are logic errors and syntactic errors. The logic errors occur due to poor understanding of the problem and solution procedure. The syntactic errors arise due to poor understanding of the language itself. ANSI C++ provides built in language features, to detect and handle exceptions which are basically run time errors. Exception handling was not part of the original C++. It is a new feature added to ANSI C++.







Try block throwing an exception:
#include
void main()
{
int a,b;
cout<< “Enter values of a and b”;
cin>>a>>b;
int x = a-b;
try
{
if(x != 0)
{
cout<<”Result(a/x0 = “ << a/x <<”\n”;
}
else //there is an exception
{
throw(x); //throws int object
}
}
catch(int i) //catches the exception
{
cout<< “exception caught : x = “<< x <<”\n”;
}
cout << “End “;
}


// example with try, multiple catch
#include
void test(int x)
{
try
{
if( x == 1) throw x; //int
else
if(x == 0 ) throw 'x'; //char
else
if(x == -1) throw 1.0; //double
cout<<"End of try block";
}
catch(char c) //catch 1
{
cout<< "Caught a character";
}
catch(int m) //catch 2
{
cout<< "Caught an integer";
}
catch(double d) //catch 3
{
cout<< "Caught a character";
}
}

void main()
{
cout<<"Testing of multiple catches ";
cout<<"X == 1";
test(1);
cout<<"X==0";
test(0);
cout<<"X==-1";
test(-1);
}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: C ++ Concept-Templates
Previous Resource: C ++ Concept-Graphics
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources


Contact Us    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.