18-09-2014, 11:35 AM
Anna University, Chennai
Department of Computer Science and Engineering
Common to B.Tech Information Technology
CS6301 Programming and Data Structure II
Unit 3 - C++ Programming Advanced Features Lecture Notes
The purpose of an abstract class (often referred to as an ABC) is to provide an appropriate base class from which other classes can inherit. Abstract classes cannot be used to instantiate objects and serves only as an interface. Attempting to instantiate an object of an abstract class causes a compilation error.
Thus, if a subclass of an ABC needs to be instantiated, it has to implement each of the virtual functions, which means that it supports the interface declared by the ABC. Failure to override a pure virtual function in a derived class, then attempting to instantiate objects of that class, is a compilation error.
Classes that can be used to instantiate objects are called concrete classes.
An exception is any unusual event, either erroneous or not, detectable by either hardware or software, that may require special processing.
Exception handling mechanism
To detect and report error
The error handling code performs the following task
1. Find the problem (Hit the exception)
2. Inform that an error has occurred.(Throw the exception)
3. Receive the error information.(Catch the exception)
4. Take corrective actions(Handle the exception).
Keywords in Exception Handling
• TRY BLOCK -The keyword try is used to preface a block of statements(surrounded by braces) which may generate exceptions.
->When an exception is detected, it is thrown using a throw statement in the try block.
• CATCH BLOCK - defined by the keyword catch ‘catches’ the exception ‘thrown’ by the throw statement in the try block, and handles it appropriately.
PDS 2 Unit 3 Notes.pdf (Size: 742.69 KB / Downloads: 1,397)
Share your Study Materials with us : Click Here