我在我的項目中使用System.Data.SQLite。當輸出文件夾中沒有System.Data.SQLite dll時,我無法捕獲FileNotFoundException(其他異常捕獲正常)。這裏是代碼exapmle:System.Data.SQLite的FileNotFoundExceptions未捕獲
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{
SQLiteConnection conn = new SQLiteConnection();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
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);
}
}
問題是什麼?