Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Why we use Fault contract instead of Try-catch block?
Posted

 
Share this answer
 
Comments
CHill60 1-May-14 10:19am    
Good link - same one I was going to use! 5'd
RahulMGunjal 1-May-14 10:27am    
Thanks!
In its simplest terms a Try/Catch block is a "local" way of handling exceptions - if you can immediately interact with your user then you would just use this and perhaps display an error message.

A Fault Contract can be used where a program is interacting with a service and allows the service to send details of an exception back to the client process (in a controlled manner)
 
Share this answer
 
Comments
Antariksh Verma 1-May-14 10:26am    
First of all thanks for your answer !! but my question is :-
We can also return an error to the client by using try catch exception.If any exception occurs we can return a string or parameter from service. so what is difference between fault contract or above way to return an error?
CHill60 1-May-14 10:43am    
Read the links in Solutions 1 and 3 and you should get the idea
You should use a fault contract because of exception shielding.

In Windows Communication Foundation (WCF), unknown exceptions are not sent to the client application to prevent details of the service implementation from escaping the secure boundary of the service.

JAFC
 
Share this answer
 
Comments
Antariksh Verma 1-May-14 10:30am    
Thanks for your answer!! But my Question is that:-
We can get error by using Try - Catch block and return through function as a string from a service then why we use Fault contract?
José Amílcar Casimiro 1-May-14 10:32am    
Read my answer carefully, and you'll understand why.

Read this article about exception management: http://msdn.microsoft.com/en-us/library/ee658105.aspx#ExceptionManagementSteps

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900