在下面的代碼中,我有一個嵌套的Try Catch。在我的嵌套catch失敗的情況下,我只想對父catch語句執行該代碼。我怎樣才能做到這一點?如何從嵌套Catch語句中轉義
try
{
try
{ // build and send invoice lines
ReadInvLinesToArray(row["ID_INVOICE"].ToString());
}
catch (Exception e)
{
writeToEventLog(e.ToString(), true, false);
SendErrorEmail("Failed to send Invoice Lines to NAV. The following system error was generated: \n" + e.ToString());
}
// send invoice header if lines have been sent
bool result = navInvoices.SendInvoicesToNAV(navImportInvoices);
// update the retrieved records, marking QB Status as value N, passing in the sql dataset as a list
UpdateQBStatusInvoiceSent(ref idInvoicesSent);
}
catch (Exception e)
{
// remove Invoice from list to ensure its status is not updated.
idInvoicesSent.Remove(Convert.ToInt32(row["ID_INVOICE"]));
WriteToEventLog(e.ToString(), true, false);
SendErrorEmail("Failed to send Invoices to NAV. The following system error was generated: \n" + e.ToString());
}
你是什麼意思失敗?你的意思是在內部捕獲中拋出異常?如果發生這種情況,那麼流程會轉到外部catch以處理該異常。 但是在外部catch中,您運行的是與內部catch相同的2個語句,因此如果內層失敗,爲什麼外層不會失敗呢? – KMoussa
外部異常將撤消對數據庫的一些修改。內部try catch與child記錄一起使用,而外部handle處理Parent記錄。如果內部失敗,那麼我需要回滾我的父記錄修改。我會修改正在發送的電子郵件。 – Gavin