开发者

try catch question

开发者 https://www.devze.com 2023-03-14 00:52 出处:网络
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

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消