protected void Button1_Click(object sender, EventArgs e)
    {        DataTable table = com.panduandenlu(username.Text, pwd.Text);//从用户表中取用户=username.Text密码=pwd.Text的记录
        try
        {
            if (username.Text == "" || username.Text != table.Rows[0]["username"].ToString() || pwd.Text != table.Rows[0]["pwd"].ToString() || code.Text == "" || code.Text != Session["codema"].ToString())
            {
                com.WebMessageBox("抱歉!登陆失败,请重试!", Request.Url.ToString());
                return;
            }
        }
        catch
        {
            com.WebMessageBox("登陆失败,请重试!",Request.Url.ToString());  //
            
            return;
        }
        Session["username"] = username.Text;
        this.stateLb.Text = table.Rows[0]["state"].ToString();
        Session["state"] = table.Rows[0]["state"].ToString();
        this.logintable.Visible = false;
        this.loginInTbl.Visible = true;
        this.usernameLb.Text = table.Rows[0]["username"].ToString();
        com.WebMessageBox("!恭喜你,登陆成功!", Request.Url.ToString());
    }
 public void WebMessageBox(string values, string PageURL)
    {
        HttpContext.Current.Response.Write("<script>alert('" + values + "');window.location.href='" + PageURL + "'</script>");
        HttpContext.Current.Response.End();
    }代码是网上下来的问题: 请问这个catch捕获的是什么异常。

解决方案 »

  1.   

    try
            {
                if (username.Text == "" || username.Text != table.Rows[0]["username"].ToString() || pwd.Text != table.Rows[0]["pwd"].ToString() || code.Text == "" || code.Text != Session["codema"].ToString())
                {
                    com.WebMessageBox("抱歉!登陆失败,请重试!", Request.Url.ToString());
                    return;
                }
            }
    这里面的异常
      

  2.   

    try 
            { 
                if (username.Text == "" || username.Text != table.Rows[0]["username"].ToString() || pwd.Text != table.Rows[0]["pwd"].ToString() || code.Text == "" || code.Text != Session["codema"].ToString()) 
                { 
                    com.WebMessageBox("抱歉!登陆失败,请重试!", Request.Url.ToString()); 
                    return; 
                } 
            } 
    这个会发生什么异常吗?
      

  3.   

    自己弄明白了,如果table中没记录就会出现异常,呵呵
      

  4.   

    这个可以不用try catch 写啊。
    会比较慢的
    情况都可以判断的出来。
    if(table==null || table.rows.count==0)
    {
    //登陆失败
    return;
    }
     if (username.Text == "" || username.Text != table.Rows[0]["username"].ToString() || pwd.Text != table.Rows[0]["pwd"])
    {
    //登陆失败
    return;
    }