我正在对 xml 文件进行反序列化,并且正在尝试使用以下代码捕获所有异常艺术之一,但它仅捕获一个异常。我在这里做错了什么?
代码:
StringBuilder exBuilder;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
var fileName = openFileDialog1.FileName;
mruOpenRseConfig.AddRecentFile(fileName);
try
{
ConfigDeserialized = MyConfig.DeserializeFromXmlFile(fileName);
}
catch (Exception ex)
{
if (ex is DataConsistencyException ||
ex is XmlException)
{
exBuilder.Clear();
exBuilder.Append(ex.Message + Environment.NewLine);
RichTextBox richTextBox = new RichTextBox();
richTextBox.Text = exBuilder;
richTextBox.Dock = DockStyle.Fill;
Form richMessageBox = new Form
{
StartPosition = FormStartPosition.CenterScreen,
ControlBox = true,
Text = "Error in File",
MaximizeBox = false,
MinimizeBox = false
};
richMessageBox.Controls.Add(richTextBox);
richMessageBox.ShowDialog();
return;
}
throw;
}
}