Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Advanced
Aug 7, 1998

Re-Throwing an Exception

An exception is thrown to indicate an abnormal state. The first handle to catch the exception can try to fix the problem. Should it fail to do that, or in case it only managed to perform a partial recovery, it can still (re-) throw the exception as long as there is a higher try-block, which has an appropriate catch-statement. In other words, try-blocks can be nested in a hierarchical order, enabling a re-thrown exception from a lower try-block's catch-statement to be caught. A re-throw is indicated by a throw without an operand:
 
class Exception {/*..*/}; //general base class for exceptions
class FileException: public Exception {/*..*/};
void main() {
File f ("db.dat");
try {
try {//inner try
			if (File.IsValid() == false )
		 	throw FileException("db.dat"); //construct FileException object and throw it
}//inner try
catch(FileException &fe)  { //first handler to cope with the exception
cout<<"invalid file specification" <
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date