我用如下代码:
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>");
}
但系统错误总是捕捉不到。
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>");
}
但系统错误总是捕捉不到。
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为数字
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>");
}
还是不能。