4

I am using the Wamp Server for back end and C# for front end. For Cheeking purpose i turn off the server. And run the program. It throw the following error in output window.

'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded            

'C:\windows\system32\System.Core.ni.dll'. Skipped loading symbols. Module is optimized and    the debugger option 'Just My Code' is enabled.

 An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary

 An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary

My Aim is Capture that Web exception into on message box. Is it possible.

I am already use the try, catch statement for capture that exception. But it's not working.

My Code

 private void Login_Click(object sender, RoutedEventArgs e)
    {
        if (string.IsNullOrWhiteSpace(this.username.Text) || string.IsNullOrWhiteSpace(this.password.Password))
        {
            MessageBox.Show("Please Enter the Username and Password");
            this.username.Text = "";
            this.password.Password = "";

        }
        else
        {

                string url = ob.localhost + "login_validate.php";
                Uri uri = new Uri(url, UriKind.Absolute);

                StringBuilder postData = new StringBuilder();
                postData.AppendFormat("{0}={1}", "username", HttpUtility.UrlEncode(this.username.Text));// txtUsername.Text));
                postData.AppendFormat("&{0}={1}", "password", HttpUtility.UrlEncode(this.password.Password.ToString()));
                try
                {
                    WebClient client = default(WebClient);
                    client = new WebClient();
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    client.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();


                    client.UploadStringCompleted += client_UploadStringCompleted;
                    //client.UploadProgressChanged += client_UploadProgressChanged;

                    client.UploadStringAsync(uri, "POST", postData.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Data.ToString());
                    MessageBox.Show(ex.GetBaseException().ToString());
                }

        }
            prog = new ProgressIndicator();
            prog.IsIndeterminate = true;
            prog.IsVisible = true;
            prog.Text = "Loading....";
            SystemTray.SetProgressIndicator(this, prog);


    }    

Please help me. Thanks in advance.

selvam
  • 1,177
  • 4
  • 18
  • 40

1 Answers1

1

try using:

  catch(Webexception ex)
  {
     Messagebox.Show(ex.innerexception.tostring());
  }
Bohrend
  • 1,467
  • 3
  • 17
  • 26