throw
In an exception handling we use try and catch. In some occasion in addition to try and catch we use throw as well. Could you tell me please when throw is necessary?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Jul 31, 2013, 1:19 PM
VulpesPosted Jul 31, 2013, 9:22 AM
However, in general, the try/catch which finally handles a re-thrown exception just needs to be in a method higher up the call stack. As the Main() method is the first method called it's always at the top of the call stack.
Where you have nested try/catch statements in the same method and an exception is rethrown from an 'inner' catch, it can also be caught in an 'outer' try/catch without the need to look for a suitable try/catch higher up the call stack.
Posted Jul 31, 2013, 8:46 AM
VulpesPosted Jul 31, 2013, 8:30 AM
Notice that by allowing the try/catch in the Main() method to handle the exception, you don't need to repeat the code in the catch block of the Divide() method:
The output is:
VulpesPosted Jul 31, 2013, 7:12 AM
Check this link for more detail:
http://msdn.microsoft.com/en-us/library/1ah5wsex(v=vs.71).aspx