<p>i have a wcf service that does an operation. and in this operation there could be a fault. i have stated that there could be a fault in my service contract. </p>

<p>here is the code below;</p>

<pre><code>public void Foo()
{
        try
        {
            DoSomething(); // throws FaultException&lt;FooFault&gt;
        }
        catch (FaultException)
        {
            throw;
        }
        catch (Exception ex)
        {
            myProject.Exception.Throw&lt;FooFault&gt;(ex);
        }
}
</code></pre>

<p>in service contract;</p>

<pre><code>[FaultException(typeof(FooFault))]
void Foo();
</code></pre>

<p>when a FaultException was thrown by DoSomething() method while i was running the application, firstly the exception was caught at "catch(Exception ex)" line and breaks in there. then when i pressed f5 again, it does what normally it has to. i wonder why that break exists? and if not could it be problem on publish?</p>

[{'answer_id': 48345, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 0, 'selected': False, 'text': '<p>Take a closer look at catched exception. Was it FaultException&lt; FooFault> or FaultException ? There are 2 version of FaultException class: <a href="http://msdn.microsoft.com/en-us/library/ms576199.aspx" rel="nofollow noreferrer">generic</a> and <a href="http://msdn.microsoft.com/en-us/library/ms576199.aspx" rel="nofollow noreferrer">non-generic</a></p>\n'}, {'answer_id': 48413, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': -1, 'selected': False, 'text': '<p>@yapiskan,</p>\n\n<p>C# is a strong typed language Foo&lt; X> != Foo. So if you need to catch some exception, provide <em>exact</em> type in <em>catch</em> clause.</p>\n\n<p>You can learn more on exception handling reading <a href="http://msdn.microsoft.com/en-us/library/ms229005.aspx" rel="nofollow noreferrer">this</a> MSDN article.</p>\n'}, {'answer_id': 284215, 'author': 'Serhat Ozgel', 'author_id': 31505, 'author_profile': 'https://Stackoverflow.com/users/31505', 'pm_score': 1, 'selected': False, 'text': '<p>Actually your exception is caught but you fail to notice it since visual studio highlights the next line, not the line throwing the exception. Replace</p>\n\n<pre><code>throw;\n</code></pre>\n\n<p>with some other lines and see them in action.</p>\n'}, {'answer_id': 295188, 'author': 'Jonathan C Dickinson', 'author_id': 24064, 'author_profile': 'https://Stackoverflow.com/users/24064', 'pm_score': -1, 'selected': False, 'text': '<p>The problem is that exceptions are checked in the order they are declared. Try putting the Exception catch block first and you will see that the compiler complains: other catch blocks will NEVER be evaluated. The following code is generally what .Net is doing in your case:</p>\n\n<pre><code>        // Begin try\n             DoSomething(); // throws FaultException&lt;FooFault&gt;\n        // End try\n        if (exceptionOccured)\n        {\n            if(exception is FaultException) // FE catch block.\n            {\n                throw;\n                // Goto Exit\n            }\n            if(exception is Exception) // EX catch block\n            {\n                throw new FaultException&lt;FooFault&gt;();\n                // Goto Exit\n            }\n        }\n\n        // Exit\n</code></pre>\n\n<p>As you can see your FaultException never re-enters the try-catch-finally (i.e. try-catch-finally is not recursive in nature).</p>\n\n<p>Try this instead:</p>\n\n<pre><code>        try\n        {\n            try\n            {\n                DoSomething(); // throws FaultException&lt;FooFault&gt;\n            }\n            catch (Exception ex)\n            {\n                if (ex is FaultException&lt;FooFault&gt;)\n                    throw;\n                else\n                    myProject.Exception.Throw&lt;FooFault&gt;(ex);\n            }\n        }\n        catch (FaultException)\n        {\n            throw;\n        }\n</code></pre>\n\n<p>HTH.</p>\n'}, {'answer_id': 1872524, 'author': 'Konamiman', 'author_id': 4574, 'author_profile': 'https://Stackoverflow.com/users/4574', 'pm_score': 2, 'selected': False, 'text': '<p>Are you consuming the WCF service from Silverlight? If so, a special configuration is needed to make the service return a HTTP 200 code instead of 500 in case of error. The details are here: <a href="http://msdn.microsoft.com/en-us/library/dd470096%28VS.96%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/dd470096%28VS.96%29.aspx</a></p>\n'}]
['https://Stackoverflow.com/questions/48340', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4215/']