我用如下代码:
float fvalue=float.Parse(TextBox1.Text.ToString())/float.Parse(Label6.Text.ToString());
Label9.Text=fvalue.ToString();

try
{
string strText=TextBox1.Text.ToString();
if (strText=="")
throw(new System.FormatException());
}
catch (System.FormatException E)
{
Response.Write(E.Message);
Response.Write("<script langeuage=vbscript>alert('待检数量不能为空')</script>");
}
但系统错误总是捕捉不到。

解决方案 »

  1.   


    try
    {
    float fvalue=float.Parse(TextBox1.Text.ToString())/float.Parse(Label6.Text.ToString());
    Label9.Text=fvalue.ToString();
    string strText=TextBox1.Text.ToString();
    if (strText=="")
    throw(new System.FormatException());
    }
    catch (System.FormatException E)
    {
    Response.Write(E.Message);
    Response.Write("<script langeuage=vbscript>alert('待检数量不能为空')</script>");
    }当字符串为空时不能parse为数字
      

  2.   

    其实你的这段代码根本不能执行到throw new formatexception,应改为这样
    try
    {
    string strText=TextBox1.Text.ToString();
    if (strText=="")
    throw(new System.FormatException());
    float fvalue=float.Parse(TextBox1.Text.ToString())/float.Parse(Label6.Text.ToString());
    Label9.Text=fvalue.ToString(); }
    catch (System.FormatException E)
    {
    Response.Write(E.Message);
    Response.Write("<script langeuage=vbscript>alert('待检数量不能为空')</script>");
    }
      

  3.   

    回 OneDotRed(武装到眼神) 
    还是不能。