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

  • Home
  • SEARCH
  • 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 8999571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:11:52+00:00 2026-06-16T00:11:52+00:00

Hi i have a program thats looking on some pages for (int i=1; i

  • 0

Hi i have a program thats looking on some pages

for (int i=1; i < 1000; i++)
{
  string id = i.ToString();
  string url_source = get_url_source("http://mysite.com/"+id);
}

and a method

    public static string get_url_source(string url)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());
        return sr.ReadToEnd();
    }

How should i change my method so the main program will just skip that url and continue to the next id when a 404-notfound occurs?

I changed my loop into this

try
            {
                string url_source = get_url_source(url);
            }
            catch(WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    ConsoleBox.Text += i + ": " + WebExceptionStatus.ProtocolError.ToString() + "\r\n";
                    continue;
                }
                else
                {
                    throw;
                }
            }
  • 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-06-16T00:11:53+00:00Added an answer on June 16, 2026 at 12:11 am

    Catch the error and check its status. If it is 404 – continue the loop, otherwise rethrow it.

    for (int i=1; i < 1000; i++)
    {
        string id = i.ToString();
        try
        {
             string url_source = get_url_source("http://mysite.com/"+id);
        }
        catch(WebException ex)
        {
            HttpWebResponse webResponse = (HttpWebResponse)ex.Response;          
            if (webResponse.StatusCode == HttpStatusCode.NotFound)
            {
                continue;
            }
            else
            {
                throw;
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that scans a big file looking for some text. Here
I am looking for a method to monitor a running program that I have
http://clifgriffin.com/blockade2/ Ok, I have an unordered list that serves as a list of menu
I'm looking to add some genetic algorithms to an Operations research project I have
I need some advice with the Java Print API. I have a program that
I have a search program that will be looking at a database from a
I have program that requires Python 3, but I develop Django and it uses
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of
I have a program that gets a JSON from the server using getJSON and

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.