我正在.net 3.5 中创建 asp.net web 应用程序,我想知道何时使用以及何时不使用 Try Catch finally 块?特别是,我的大部分尝试捕获都围绕执行存储的过程和填充文本字段或网格视图?当您执行存储过程并填充数据显示控件时,您会使用 Try Catch EVERYTIME吗?
我的代码块通常如下所示:
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
{ }
}