title: WCF ASync ...Lost Exception at Client Side
body: <p>I try to learn WCF, so I play with an simple  WCF application, From Source Stephen Cleary => <a href="http://blog.stephencleary.com/2012/08/async-wcf-today-and-tomorrow.html?showComment=1381402644286#c7760085323662285363" rel="nofollow">async-wcf-today-and-tomorrow </a></p>
  
  <p>Here is the code fragments:</p>
  
  <p>Simple Contracts:</p>
  
  <pre><code>[DataContract]
  public class CalculatorFault
  {
    [DataMember]
    public string Message { get; set; }
  }
  
  [ServiceContract]
  public interface ICalculator
  {
  
    [OperationContract]
    [FaultContract(typeof(CalculatorFault))]
    Task&lt;uint&gt; DivideAsync(uint numerator, uint denominator);
  }
  </code></pre>
  
  <p>Simple Service Implementation:</p>
  
  <pre><code>public class Calculator : ICalculator
  {
    public async Task&lt;uint&gt; DivideAsync(uint numerator, uint denominator)
    {
      try
      {
        var myTask = Task.Factory.StartNew(() =&gt; numerator / denominator);
        var result = await myTask;
        return result;
      }
      catch (DivideByZeroException)
      {
        throw new FaultException&lt;CalculatorFault&gt;(new CalculatorFault { Message = "Undefined result" });
      }
    }
  }
  </code></pre>
  
  <p>And Simple Call From Client:</p>
  
  <pre><code>static class Program
  {
    static async Task CallCalculator()
    {
      try
      {
        var proxy = new CalculatorClient();
        var task = proxy.DivideAsync(10, 0);
        var result = await task;
        Console.WriteLine("Result: " + result);
      }
      catch (FaultException&lt;CalculatorFault&gt; ex)
      {
        Console.Error.WriteLine("Error: " + ex.Detail.Message);
      }
    }
  
    static void Main(string[] args)
    {
      try
      {
        CallCalculator().Wait();
      }
      catch (Exception ex)
      {
        Console.Error.WriteLine(ex);
      }
  
      Console.ReadKey();
    }
  }
  </code></pre>
  
  <p>And it works: When I try to divide a number with zero, I got the exception from client.</p>
  
  <p><strong>But What I want to do is delegate WCF Call  to other functions like old callback functions.So I try the following at client side</strong></p>
  
  <pre><code>async Task CallCalculator()
  {
      try
      {
           var task = channel.DivideAsync(10, 0);
           task.ContinueWith(OnWorkCompleted); 
      }
     catch (FaultException&lt;CalculatorFault&gt; ex)
      {
          Console.Error.WriteLine("Error: " + ex.Detail.Message);
      }
  
  }
  
  void OnWorkCompleted(Task&lt;uint&gt; task)
  {      
       var result = task.Result;
      Console.WriteLine("Result From Async: " + result);
  }
  </code></pre>
  
  <p><strong>And this also works, but when I try to attempt divide by zero, I got no exception, no result from client although service throw Exception.</strong></p>
  
  <p>Why this may happen? How can I fix it to catch  exception from client side?</p>