user20358
user20358

Reputation: 14736

try catch question

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?

Upvotes: 4

Views: 151

Answers (2)

Tomas Jansson
Tomas Jansson

Reputation: 23472

Yes, you should use throw and not throw f. If you don't do anything in the catch statement you can leave out the catch.

Upvotes: 3

Oded
Oded

Reputation: 499062

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.

Upvotes: 6

Related Questions