处理可预料的异常处理(try-catch-finally)
Try
{
//添加可能会产生异常信息的代码(个人觉得数据库连接到关闭那块运用感觉很好)
}
Catch()
{
//添加异常处理的信息的代码或throw语句将特定的异常抛出
}
Finally
{
//添加释放占用资源的代码
}
如例子:
try
{conn.ConnectionString =System.Configuration .ConfigurationSettings .AppSettings ["dsn"];
conn.Open ();
Sqlandtable();
}
catch(Exception tt)
{
HttpContext.Current.Response.Write(tt.Message);
HttpContext.Current.Response.End();
//Response.Write (tt);
}
finally
{
conn.Close ();
}