收集内部异常然后向用户显示消息的好方法是什么?

时间:2018-04-23 10:46:45

标签: c# .net exception exception-handling

我有一系列方法。在每个方法中,我都尝试/捕获块,如下例所示:

public void DoCommand() {
    try {
        GetData();
    }
    catch(Exception ex) {
        // I want to show the following and all inner exceptions
        // in correct order here (User-friendly stack trace)
    }
}

public void GetData() {
    try {
        GetLowLevelData();
    }
    catch(Exception ex) {
        throw new Exception("Get Data exception", ex);
    }
}

public void GetLowLevelData() {
    try {
        // do something
    }
    catch(Exception ex) {
        throw new Exception("Get Low Level Data exception", ex);
    }
}

收集内部异常以在DoCommand方法中记录它的好方法是什么?

0 个答案:

没有答案