我在我的项目中使用 System.Data.SQLite。当输出文件夹中没有 System.Data.SQLite dll 时,我无法捕获 FileNotFoundException(其他异常捕获良好)。这是代码示例:
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
SQLiteConnection conn = new SQLiteConnection();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
消息框未显示。如果我在单独的函数中提取此代码并将此函数调用包装在 try catch 中,则捕获异常工作正常并且 MessageBox 显示:
private void DeclareConnection()
{
SQLiteConnection conn = new SQLiteConnection();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
DeclareConnection();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
问题是什么?