Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

try catch question

Tags:

c#

exception

wcf

Im doing this in c#. These are the code layers

VIEW -> VIEWHANDLER -> BusinessLayer -> WCF SERVICE

The view calls the ViewHandler which calls the business layer which calls the service. The service will throw some fault exception. All exceptions are handled in the View handler. The business layer re-throws the fault exception it got from the service as is to be handled in the VIEWHANDLER. What is the best way to rethrow it in the BusinessLayer?

catch(FaultException f)
{
throw f;
}

or

catch(FaultException f)
{
throw;
}

Does "throw f" resets the call stack information held in the caught exception? and does throw send it as-is?

like image 981
user20358 Avatar asked Jan 19 '23 11:01

user20358


1 Answers

Yes, throw f; will reset the stack.

throw; will not.

In either case, if this is all you are doing in the catch block, you are better off not using a try-catch block at all as it is pointless.

like image 92
Oded Avatar answered Jan 27 '23 13:01

Oded