catch()
{
Response.Write("<script language='javascript'>alert('错误啦,哈哈!')</script>");
}

解决方案 »

  1.   


    try
    {
    mycommand.Fill(mydataset,"album");
    }
    catch(Exception e)
    {
           throw new Exception("要显示的出错信息",e);             
    }
    在页面中使用该方法的地方:albumdb db=new db();
       .
       .
       .
    try
    {
       db.getalbums(..);
    }
    catch(Exception ex)
    {
       Response.Write("<script>alert('"+ex.Message+"')</script>");
       Response.End();}
      

  2.   

    其实,我觉得你最应该做的事情是在用户输入日期数据的aspx中加入有效检查控件RegularExpressionValidator。通过正则表达式限制用户输入的数据必须是有效的日期字符串。这样,你的代码就根本不会出错啦.
    有关的例子,你可以在以下链接中找到:
    http://samples.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/regexvalidator/doc_regexval.aspx
      

  3.   

    谢谢楼上,不过出了错后,如何返回此页,而不仅仅是终止执行,我在Response.End();前加了一句Response.Redirect("album.aspx");但错误信息就不弹出了,怎么回事呢?
      

  4.   

    jl1024(CS领导者) :
    检查控件RegularExpressionValidator我也加了,但只能确保用户输入格式为****-**-**的日期,没法判断是否合法日期,不知哪位有这样的表达士,我的是\d{4}(-|/)\d{2}(-|/)\d{2}
      

  5.   

    我在Response.End();前加了一句Response.Redirect("album.aspx");但错误信息就不弹出了,怎么回事呢?
    出错后立刻转走你当然看不见啦
    我建议也是多加一个参数
      

  6.   

    history.back();这样就可以了:^o^
    ----------------------------------------
    try
    {
       db.getalbums(..);
    }
    catch(Exception ex)
    {
       Response.Write("<script>alert('"+ex.Message+"');history.back();</script>");
       Response.End();}