Is it possible to handle exceptions within LINQ queries?


myEnumerable.Select(a => ThisMethodMayThrowExceptions(a));

How to make it work even if it throws exceptions? Like a try catch block with a default value case an exceptions is thrown…


myEnumerable.Select(a => 
      return ThisMethodMayThrowExceptions(a));
      return defaultValue;

But actually, it has some smell.

About the lambda syntax:

x => x.something

is kind of a shortcut and could be written as

(x) => { return x.something; }

Leave a Reply

Your email address will not be published. Required fields are marked *