Forum
Resources
Mentors
Projects
Entrance Exams
Question Papers
Colleges
Courses
Universities
Schools
Make Money
Members
Bookmarks
Polls
Fresher Jobs
Funny Pictures
MCA Projects
New Member FAQ
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
pradeep
(61)
prathyusha
(25)
nazikha
(18)
Last 7 Days
bharath sudar
(5514)
palvir
(4684)
Nitin Bajaj ...
(3018)
more...
Awards & Gifts
Online Exams
Aptitude Questions
General Aptitude Tests
Medical Entrance
Engineering Entrance
Bank Tests
TOEFL & IELTS Questions
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
Watch Asianet TV online
Kairali TV in Internet
Surya TV online
Amritha TV Channel
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
Sign In
(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
C Program -Calculation of bonus
Network security career opportunities
C Program to implement Macro Processor
Back up your online data for free
C Program for addition and deletion of nodes and edges in a graph
Contact Us
Privacy Policy
Terms Of Use
SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.