going back from catch to try-webspider

Discussion in 'Java' started by ameerov@gmail.com, Nov 18, 2005.

  1. Guest

    I'm writing a webspider. When a bad url is encountered then a
    MalformedURLException is thrown. What I want to do is ignore this bad
    URL's exception and continue reading the other urls.

    I'm not very familiar with try catch blocks but as I understand there
    is no way to go from catch BACK TO the try .(After encountering an
    exception)

    So then how is it possible to ignore this exception and thus SKIP
    reading the bad URL so I can continue reading the good ones ?

    Thanks.
    , Nov 18, 2005
    #1
    1. Advertising

  2. wrote:

    > I'm writing a webspider. When a bad url is encountered then a
    > MalformedURLException is thrown. What I want to do is ignore this bad
    > URL's exception and continue reading the other urls.
    >
    > I'm not very familiar with try catch blocks but as I understand there
    > is no way to go from catch BACK TO the try .(After encountering an
    > exception)


    It depends, if the try/catch is entirely inside a loop, the
    loop itself can continue.

    A better group for those new to Java is
    <http://www.physci.org/codes/javafaq.jsp#cljh>

    --
    Andrew Thompson
    physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
    Currently accepting short and long term contracts - on Earth.
    Andrew Thompson, Nov 18, 2005
    #2
    1. Advertising

  3. Bjorn Abelli Guest

    <> wrote...

    > I'm writing a webspider. When a bad url is encountered
    > then a MalformedURLException is thrown. What I want to
    > do is ignore this bad URL's exception and continue reading
    > the other urls.
    >
    > I'm not very familiar with try catch blocks but as I
    > understand there is no way to go from catch BACK TO
    > the try .(After encountering an exception)
    >
    > So then how is it possible to ignore this exception and
    > thus SKIP reading the bad URL so I can continue reading
    > the good ones ?


    That depends on your specific implementation.

    Lets say that you have all urls as strings in a list of some sort.

    Then you iterate through them somehow, e.g:

    for (int i = 0; i < numberOfUrls; i++)
    {
    String url = (String) listOfUrls.get(i);

    try
    {
    // Some parsing or whatever, that can
    // throw a MalformedURLException

    // Here you proceed on the urls that hasn't
    // thrown a MalformedURLException
    }
    catch (MalformedURLException mux)
    {
    // Here you do whatever you want, e.g.
    // write the String url to a logfile, to
    // check at a later time.
    }
    }

    // Bjorn A
    Bjorn Abelli, Nov 18, 2005
    #3
  4. Roedy Green Guest

    On 18 Nov 2005 07:05:38 -0800, wrote, quoted or
    indirectly quoted someone who said :

    >So then how is it possible to ignore this exception and thus SKIP
    >reading the bad URL so I can continue reading the good ones ?


    you put a try block around the whole thing so if anything fails it
    jumps to the end.
    where you can do a finally close.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 18, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JenHu
    Replies:
    2
    Views:
    395
    William F. Robertson, Jr.
    Jan 28, 2005
  2. bienwell
    Replies:
    4
    Views:
    3,738
    bienwell
    May 27, 2005
  3. Chris
    Replies:
    2
    Views:
    287
    Chris
    Jun 13, 2007
  4. Replies:
    2
    Views:
    214
    alex23
    May 24, 2008
  5. Replies:
    1
    Views:
    353
    John Nagle
    May 25, 2008
Loading...

Share This Page