可能重複:
Catching specific vs. generic exceptions in c#C#異常處理,使用哪個catch子句?
下面是一個例子方法
private static void outputDictionaryContentsByDescending(Dictionary<string, int> list)
{
try
{
//Outputs entire list in descending order
foreach (KeyValuePair<string, int> pair in list.OrderByDescending(key => key.Value))
{
Console.WriteLine("{0}, {1}", pair.Key, pair.Value);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Error detected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
我想知道從剛剛Exception
除了使用什麼例外條款,如果有一個在使用更具體的catch子句方面具有優勢。
編輯:O.k感謝大家
如果'list'爲null,'outputDictionaryContentsByDescending'應拋出'ArgumentNullException' – 2014-01-06 16:43:26