Here is a sample code:
public IList<LogEntry> ReadLogs(Guid id, string name) { var logs = this.RetrieveLogs(id, name); if (logs != null) { foreach (LogEvent logEvent in logs) { // bla, bla, bla } } return logEntries; } private IEnumerable<LogEvent> RetrieveLogs(Guid id, string name) { try { FilterCriteria filterCriteria = CreateFilterCriteria(); return (from log in this.loggingProvider.ReadLogs(filterCriteria, 1) where log.ParticipantObjects[0].ParticipantObjectId == id.ToString() && log.LogEventParameters[0].Value == name orderby log.Timestamp.ToLocalTime() descending select log).AsEnumerable(); } catch (Exception ex) { this.tracer.Write(Category.Error, ex, "Error"); return null; } }
Now, if there was an exception in the loggingProvider.ReadLogs() method, it will be caught and traced. But if, for example, there is no ParticipantObjects[0] , this exception will not be caught and traced here. This seems to have something to do with lambda expressions and closures.
What is the explanation?
source share