![]() |
|
#1
|
|||
|
|||
Throwing exceptionsThe documentation I've found is a little hazy on this subject, so it's time to fire off yet another no-doubt ignorant question:
Is "throw" intended exclusively for the following scenario: Control is transferred out of a try block via a method call, and code in the called method then detects an exception, so the called method uses "throw" to transfer control back to the appropriate catch block associated with the original try block? |
|||
|
#2
|
|||
|
|||
Re: Throwing exceptionsA throw is intended for when you wish to raise a exception. The exception is caught by whatever section of calling code you want to handle it.
If you have several calling methods each with a try..catch statement and you wanted to get to the top calling method inorder to handle to exception you could continue to throw the exception, until that top calling method is reached and the the exception is handled. However, you should only use a try..catch when that segment of calling code can deal with the exception. Catching an exception to then rethrow it is generally useless. |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_all | upadhyad | C++ Forum | 8 | 12-Jul-2008 16:42 |
| how to get instruction after exceptions? | baccardi | Assembly Language | 0 | 03-Dec-2007 15:19 |
| Memory Allocation Exceptions in C++ | David52 | C++ Forum | 10 | 19-Apr-2006 14:13 |
| Need help with "atol". Exceptions handling? | nikp | C++ Forum | 1 | 02-Dec-2005 09:51 |
| throwing an struct(with an array) through a function | knakworstje | C Programming Language | 5 | 15-Feb-2004 17:20 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The