相关疑难解决方法(0)

"throw"和"throw 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.
    }
}
Run Code Online (Sandbox Code Playgroud)

如果try & catch用于Main,那么我会throw; …

.net c# exception-handling exception

414
推荐指数
8
解决办法
18万
查看次数

标签 统计

.net ×1

c# ×1

exception ×1

exception-handling ×1