Last post Aug 24, 2014 04:36 AM by gerrylowry
Aug 24, 2014 02:32 AM|bsurendiran|LINK
lets say i have function
public void DoWork()
catch (CustomException ex) // Catch 1
throw new Exception(ex.Message);
catch (Exception ex) //Catch2
* Will the exception thrown in Catch 1 will be catched in Catch2 ?
Aug 24, 2014 02:40 AM|MetalAsp.Net|LINK
No. Only the first catch. Only one catch block will be hit.
Aug 24, 2014 04:36 AM|gerrylowry|LINK
@bsurendiran welcome to forums.asp.net
if you do not have a try/catch, exceptions will be caught at some higher level in the call stack, or missed altogether and caught by the operating system ~~ worst case scenario, if the operating system can not catch the exception, you likely will crash your
Think of an exception as a bubble from the bottom of the ocean; as it bubbles up to the surface, it may get trapped on the way up to the top.
important, exceptions are hierarchical; for that reason, when you have multiple catch blocks, you stack them from more specific to less specific, if you try to stack them the wrong way around, the c# compiler will not let you.
catch (Exception ex)
catch (DivideByZeroException zdivex) // error
error: A previous catch clause already catches all exceptions
of this or of a super type ('System.Exception')
"Handling and Throwing Exceptions"
you can throw and/or rethrow exceptions. see http://www.dotnetperls.com/throw (generally, you should be careful so as to not mess up your