0
我有一段代碼看網絡共享。一個錯誤是UnauthorizedAccessException,如果我需要使用基本身份驗證來訪問共享,則會發生這種情況。catch塊下面的代碼(關閉後)還是不是?
因爲這個問題,如果你登陸的時候彈出在異常的時間中出現時消失了,並在今年秋天異常下可處理?此外,這將是一個好主意,寫:
string[] directories = null;
try
{
directories = Directory.GetDirectories(path);
}
catch (UnauthorizedAccessException unauthorizedAccessException)
{
Logger.Error(unauthorizedAccessException.Message, unauthorizedAccessException);
MessageBox.Show("An error has occur. Please check that you do not need to sign in to access the share. " + unauthorizedAccessException.Message, UiConstants.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
}
...更多的代碼,這裏...
,或者在try塊,插入的所有代碼。我的印象是,如果異常可以恢復,那麼可以在catch塊下面有代碼。構建這樣的代碼的最好方法是什麼?