GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Feb-2009, 11:29
BobLewiston BobLewiston is offline
Junior Member
 
Join Date: Nov 2008
Posts: 46
BobLewiston is on a distinguished road

Throwing exceptions


The 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  
Old 06-Apr-2009, 07:29
erniegerdie erniegerdie is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: England
Posts: 93
erniegerdie has a spectacular aura abouterniegerdie has a spectacular aura about

Re: Throwing exceptions


A 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 GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 17:30.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.