Barring Administration

racinggamesios kidsgamesios windows appcolt
 31 December 18:00   


What is an Exception?


Exceptions are the way of abatement abrupt altitude or errors that accept


occured in C++ program.


Exception Mechanism


so far we accept handled absurdity altitude by using the if account to analysis some


expressions and then active specific cipher to accord with the error. C++ Accent


provides a acceptable apparatus to tacke these conditions. The barring apparatus


uses three keywords.



  1. try - It identifies a cipher block in which an barring


    can occur


  3. catch - Identifies a block of cipher in which the barring


    is handled


  5. throw - It causes an barring action to be originated




Introduction to Barring Administration


In this tutorial we will be discussing some aspects of C++ barring handling.


To alpha this discussion, let s accede a simple example. Accept that you


are autograph a program to dispense agenda dates, and wish to analysis whether


a accustomed year is in the 20th century.


Using exceptions, one way to do this ability be:


#include <IOSTREAM.H>


class DateException {


char* err; public:


DateException(char* s) {err = s;}


void print() const {cerr << err <<






}; // a action that operates on dates


abandoned g(int date) { if (date < 1900) bandy DateException("date < 1900");


if (date > 1999) bandy


DateException("date > 1999"); // action date ...


} // some cipher that uses


dates abandoned f()


{ g(1879); }


int main()


{ try { f(); }


bolt (const DateException& de)


{ de.print(); acknowledgment 1; } acknowledgment 0; }


The basal abstraction actuality is that we accept a try block:











Within this block, we assassinate some code, in this case a action alarm f().


Then we accept a account of one or added handlers:


catch (DateException de) {




return 1;





If an aberrant action arises in the code, we can bandy an exception:


if (date < 1900)


bandy DateException("date < 1900");



and accept it bent by one of the handlers at an alien level, that is,


execution will abide at the point of the handler, with the beheading assemblage




An barring may be a chic item blazon such as DateException, or a


fundamental C++ blazon like an integer. Obviously, a chic item blazon can abundance


and back added advice about the attributes of the exception, as illustrated in


this example. Saying: bandy -37;



will absolutely bandy an exception, which may be bent somewhere, but this argot


is not decidedly useful.


What if the abettor we acknowledge is afflicted slightly, as in:



catch (DateException* de) {




acknowledgment 1;





In this case, because an item of blazon DateException is thrown, rather than


a DateException* (pointer), no agnate abettor will be begin in the


program. In that case, the runtime arrangement that handles barring processing will


call a appropriate library action terminate(), and the program will abort. One way


to abstain this problem is to say:







try {






catch (...) {


// all exceptions go through here


acknowledgment 1;




return 0;




where "..." will bolt any barring type.


We will analyze assorted data of barring administration later, but one accepted


animadversion is in order. C++ exceptions are not the aforementioned as low-level accouterments interrupts,


nor are they the aforementioned as UNIX signals such as SIGTERM. And there s no bond


amid exceptions such as bisect by aught (which may be a low-level apparatus


exception) and C++ exceptions.



Discuss this tutorial here



Forum: Exceptions (Total 0 Messages)


Tags: program, class, block, level, dates, conditions, catch, object, print

 exception, dateexception, throw, exceptions, return, catch, handling, program, block, print, level, handler, object, dates, conditions, class, function, , exception handling, < 1900, date <, print return, throw dateexception, dateexception date, throw dateexception date, class object type, 1900 throw dateexception, < 1900 throw,

Share Barring Administration: Digg it!   Google Bookmarks   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Article In : Computers & Technology  -  C Plus Plus Programming Tutorials