小编bre*_*ree的帖子

try catch块中的代码重复

是否有更好的方法来捕获异常?我好像在复制很多代码.基本上在每个控制器中我都有一个catch语句来执行此操作:

try
{
     Do  something that might throw exceptions.
}
catch (exception ex)
{
     Open database connection
     Save exception details.
     If connection cannot be made to the database save exception in a text file.
}
Run Code Online (Sandbox Code Playgroud)

我在每个控制器中有4个控制器和大约5-6个动作方法,这是很多代码重复.如何减少上面try catch语句中的行数?

c# exception-handling asp.net-mvc-4

23
推荐指数
3
解决办法
2057
查看次数

标签 统计

asp.net-mvc-4 ×1

c# ×1

exception-handling ×1