<分区>
Possible Duplicate:
Catching specific vs. generic exceptions in c#
这是一个示例方法
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 子句是否有优势。
编辑:好的,谢谢大家