我把代码重新排版一下:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
……
#region Initialize Method
public pub() {
this.cn = new SqlConnection();
this.cn.ConnectionString = "data source=\"NORSSION-SERVER\";user id=sa;password=c00202";
try {
cn.Open();
}
catch( Exception ex ) {
string s = ex.GetType().FullName;
System.Diagnostics.Debug.WriteLine( s );
switch( s ) {
case "System.Data.SqlClient.SqlException":
//show some message
//我想在这里写抛出的异常消息,怎么写?用Response.Write不行
break;
case "System.InvalidCastException":
case "System.NullReferenceException":
case "System.Exception":
//show some message
//我想在这里写抛出的异常消息,怎么写?用Response.Write不行
break;
default:
//Unknown class of exception
//show some message
//我想在这里写抛出的异常消息,怎么写?用Response.Write不行
break;
}
}
}
#endregion
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
……
#region Initialize Method
public pub() {
this.cn = new SqlConnection();
this.cn.ConnectionString = "data source=\"NORSSION-SERVER\";user id=sa;password=c00202";
try {
cn.Open();
}
catch( Exception ex ) {
string s = ex.GetType().FullName;
System.Diagnostics.Debug.WriteLine( s );
switch( s ) {
case "System.Data.SqlClient.SqlException":
//show some message
//我想在这里写抛出的异常消息,怎么写?用Response.Write不行
break;
case "System.InvalidCastException":
case "System.NullReferenceException":
case "System.Exception":
//show some message
//我想在这里写抛出的异常消息,怎么写?用Response.Write不行
break;
default:
//Unknown class of exception
//show some message
//我想在这里写抛出的异常消息,怎么写?用Response.Write不行
break;
}
}
}
#endregion
throw ex;如果要抛出一个新的异常:throw new ApplicationException("异常信息");或者:throw new 自己的异常类();
HttpContext.Current.Response.Write("<script>alert('Hello');</script>");
抛出异常,只是说明程序有异常发生!如要的到你的结果:
try
.....
catch execption e
this.registerstartupscript("err1","<script language='javascript'>alert('faint');</script>")
finally
...
end try
LineCorner(),你说的方法我也看到过,但是使用后并没有任何效果啊。我的代码如下:
using System.Web.UI;
……
Page p = new Page();
p.RegisterStartupScript("err1", "<script>alert('Hello');</script>");
……
应该怎么改?
p.RegisterStartupScript("err1", "<script>alert('Hello');</script>");