首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何捕获windows phone 8中的Web异常?

如何捕获windows phone 8中的Web异常?
EN

Stack Overflow用户
提问于 2013-07-22 20:58:40
回答 1查看 699关注 0票数 4

我使用Wamp服务器作为后端,使用C#作为前端。出于检查的目的,我关闭了服务器。然后运行程序。它会在输出窗口中抛出以下错误。

代码语言:javascript
运行
复制
'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

我的目标是将Web异常捕获到on message框中。有没有可能。

我已经在使用try,catch语句来捕获该异常。但它不起作用。

我的代码

代码语言:javascript
运行
复制
 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);


    }    

请帮帮我。提前谢谢。

EN

Stack Overflow用户

发布于 2013-07-22 21:23:16

尝试使用:

代码语言:javascript
运行
复制
  catch(Webexception ex)
  {
     Messagebox.Show(ex.innerexception.tostring());
  }
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17788250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档