有一些帖子问这两者之间的区别是什么。
(为什么我要提这件事……)
但我的问题不同之处在于,我在另一种类似神的错误处理方法中调用“抛出ex”。
public class Program {
public static void Main(string[] args) {
try {
// something
} catch (Exception ex) {
HandleException(ex);
}
}
private static void HandleException(Exception ex) {
if (ex is ThreadAbortException) {
// ignore then,
return;
}
if (ex is ArgumentOutOfRangeException) {
// Log then,
throw ex;
}
if (ex is InvalidOperationException) {
// Show message then,
throw ex;
}
// and so on.
}
}
如果在Main
中使用try & catch
,那么我将使用throw;
重新抛出错误。但在上面简化的代码中,所有异常都通过HandleException
当在HandleException
内部调用时,throw ex;
是否具有与调用throw
相同的效果
https://stackoverflow.com/questions/730250
复制相似问题