我正在使用 .net 3.5 创建 asp.net 网络应用程序,想知道何时使用 Try Catch Finally 块,何时不使用?尤其是,大部分的 try catch 都包裹在执行存储过程和填充文本字段或网格视图方面。您会在执行存储过程和填充数据显示控件时每次都使用 Try Catch 吗?
我的代码块通常如下所示:
protected void AddNewRecord()
{
try
{
//execute stored proc
// populate grid view controls or textboxes
}
catch (Exception ex)
{
//display a messagebox to user that an error has occured
//return
}
finally
{ }
}