Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4531842
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:57:15+00:00 2026-05-21T13:57:15+00:00

Say I write a linq query for info about the hidden files on my

  • 0

Say I write a linq query for info about the hidden files on my C drive:

var q2 =
    from c in Directory.EnumerateFiles("C:\\")
    where Regex.IsMatch(c, @"^C:\\\.")
    select c;

var q3 =
    from c in q2
    let info = new 
    {
        File = c,
        FileSecurity = File.GetAccessControl(c),
        FileAttributes = File.GetAttributes(c),
        CreatedUTC = File.GetCreationTimeUtc(c),
        AccessedUTC = File.GetLastAccessTimeUtc(c),
        ModifiedUTC = File.GetLastWriteTimeUtc(c)
    }
    select info;

The above is an example of logic that might want to keep going when an exception is caught, but I don’t know how to get that to happen in this style of C# programming (or if its possible).

Conceptually I want some kind of “continue” statement that can be put in the body of a catch block surrounding a LINQ query.

try
{
   // LINQ QUERY
}
catch(Exception ex)
{
  Logger.Log("error...");
  continue;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T13:57:16+00:00Added an answer on May 21, 2026 at 1:57 pm

    Due to the lazy nature of LINQ you might need to try/catch when you start consuming the iterator and not when building the query:

    var q3 = ...
    
    try
    {
        foreach (var item in q3)
        {
            ...
        }
    } 
    catch(Exception ex)
    {
    
    }
    

    The Directory.EnumerateFiles simply returns an IEnumerable<string> and no evaluation happens until you start iterating over it.


    UPDATE:

    To avoid breaking out of the loop if an exception is thrown you could do the following:

    static void Main()
    {
        var q = Enumerable.Range(1, 5).Select(x =>
        {
            if (x % 2 == 0)
            {
                throw new Exception();
            }
            return x;
        });
    
        using (var enumerator = q.GetEnumerator())
        {
            while (true)
            {
                try
                {
                    bool hasNext = enumerator.MoveNext();
                    if (!hasNext)
                    {
                        break;
                    }
    
                    Console.WriteLine(enumerator.Current);
                }
                catch (Exception ex)
                {
                    // TODO: do something with the exception here
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I write this: from subprocessing import Popen, STDOUT, PIPE p = Popen([myproc], stderr=STDOUT,
say I'm about to write an application with a thin GUI layer, a really
Is it possible to extract sql statements from LINQ queries ? Say, I have
How would one write a LINQ query which takes a hierarchical source data and
I'm trying to write Linq query on this Products table based on FacetTypes that
Basically I want to write a linq query to order the number of days
Let's say that you want to write an application that processes multiple text files,
Say I wanted to write a program that would export calendar data so that
I'd confidently say 99% of applications we write don't need to address more than
If I write a serialversionUid for my class as say 1234, and I know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.