Surround GetItemFromId with try/catch block
authorThomas
Thu, 27 Jul 2017 08:48:13 +0200
changeset 176332710d41075b
parent 1762 6114ad58e90a
child 1764 6399bdbc042c
Surround GetItemFromId with try/catch block
ThisAddIn.cs
     1.1 --- a/ThisAddIn.cs	Wed Jul 26 14:26:44 2017 +0200
     1.2 +++ b/ThisAddIn.cs	Thu Jul 27 08:48:13 2017 +0200
     1.3 @@ -3221,7 +3221,16 @@
     1.4                  if (this.TryPopDecryptionStack(out entryId))
     1.5                  {
     1.6                      // Get mail item and set process flag to true
     1.7 -                    omi = this.Application.Session.GetItemFromID(entryId);
     1.8 +                    try
     1.9 +                    {
    1.10 +                        omi = this.Application.Session.GetItemFromID(entryId);
    1.11 +                    }
    1.12 +                    catch (Exception ex)
    1.13 +                    {
    1.14 +                        omi = null;
    1.15 +                        Log.Error("DecryptionTimer_Tick: Error getting item from ID. " + ex.ToString());
    1.16 +                    }
    1.17 +
    1.18                      if (omi != null)
    1.19                      {
    1.20                          process = true;
    1.21 @@ -3456,7 +3465,7 @@
    1.22          /// Event handler for when one or more new mail items are received.
    1.23          /// See: https://msdn.microsoft.com/en-us/library/office/ff869202.aspx
    1.24          /// </summary>
    1.25 -        /// <param name="entryIdCollection">A collection of EntryID's (separated by ',')
    1.26 +        /// <param name="entryIdCollection">A collection of EntryIDs (separated by ',')
    1.27          /// for each new mail item.</param>
    1.28          private void Application_NewMailEx(string entryIdCollection)
    1.29          {
    1.30 @@ -3490,7 +3499,10 @@
    1.31                              Log.Verbose("Application_NewMailEx: item is already being processed.");
    1.32                          }
    1.33                      }
    1.34 -                    catch { }
    1.35 +                    catch (Exception ex)
    1.36 +                    {
    1.37 +                        Log.Error("Application_NewMailEx: Error processing item entryId. " + ex.ToString());
    1.38 +                    }
    1.39                  }
    1.40              }
    1.41