Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 asp.net 零框架的新手。我只是想知道是否有任何原因导致示例 asp.net 代码不使用 Application Service 文件夹中的 try catch 块。例如,我们已经包含了下面的示例代码 - 似乎没有包含 try 和 catch 是有原因的,但为什么呢?
try/catch不是你“仅仅因为”添加的东西 - 你会添加它是因为在某些预期异常的情况下你可以做一些有用的事情。那么,大概没有适用于此的场景。预计不会发生异常,因此如果确实发生了:出了点问题,就让它引发吧。您不应该养成在没有充分理由的情况下隐藏异常的习惯(例如:您已经处理了预期的失败并成功恢复)。
try
catch
在许多方面,try/finally在大多数代码中应该比try/更常见catch,即使那样,它也应该主要是编译器生成的using。
finally
using