Re-Throwing an Exception

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 exceptionsclass 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 trycatch(FileException &fe)  { //first handler to cope with the exceptioncout


Share the Post: