title: In Silverlight, how do I handle an error during an asynchronous call?
body: <p>In my SL4 app, I have a call to a service, svc.SubmitAsync(). Since this is an async call, once the method is hit, my code goes on to the next line. This is fine as long as the user enters the correct user name and password. If they don't, EndSubmit() throws an exception. EndSubmit() is in References.cs, part of the auto-generated Silverlight code.</p>
  
  <p>I tried wrapping svc.SubmitAsync() in a try-catch but this is an async call and the try-catch block completes before the exception is even thrown.</p>
  
  <p>How do I catch this error?</p>
  
  <p>Thanks!</p>
  
  <p>Update 1</p>
  
  <pre><code>public void SubmitTweetAsync(TestSilverlightApp.svc.Tweet tweet, object userState) {
              if ((this.onBeginSubmitTweetDelegate == null)) {
                  this.onBeginSubmitTweetDelegate = new BeginOperationDelegate(this.OnBeginSubmitTweet);
              }
              if ((this.onEndSubmitTweetDelegate == null)) {
                  this.onEndSubmitTweetDelegate = new EndOperationDelegate(this.OnEndSubmitTweet);
              }
              if ((this.onSubmitTweetCompletedDelegate == null)) {
                  this.onSubmitTweetCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnSubmitTweetCompleted);
              }
              base.InvokeAsync(this.onBeginSubmitTweetDelegate, new object[] {
                          tweet}, this.onEndSubmitTweetDelegate, this.onSubmitTweetCompletedDelegate, userState);
          }
  </code></pre>
  
  <p>Update 2 - This is a WCF service.</p>