0

If I want to preserve the stack trace and I have this catch block...

try
{
    //Cause exception here...
}
catch (CustomException customEx)
{
    //Handle custom exception here...
}
catch
{
    throw;
}

Will the above catch (without parameter) rethrow the exception?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263

2 Answers2

3

Your question is unclear. Your actual question seems to be "Does a catch(SpecificException) fall through to the general catch?", to which the answer is "no".

If by "the" exception you mean "any other exception than CustomException", then yes, they will be rethrown.

If you want to rethrow the latter too, you'll also need a throw in the catch(CustomException customex).

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
0

you can use try-catch-finally

A common usage of catch and finally together is to obtain and use resources in a try block, deal with exceptional circumstances in a catch block, and release the resources in the finally block. For more information and examples on re-throwing exceptions, see try-catch and Throwing Exceptions. For more information about the finally block, see try-finally.

for more details see

https://msdn.microsoft.com/en-us/library/dszsf989.aspx

Imran Ali Khan
  • 8,469
  • 16
  • 52
  • 77