Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

going back from catch to try-webspider

Thread view: 
ameerov@gmail.com - 18 Nov 2005 15:05 GMT
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.
Andrew Thompson - 18 Nov 2005 15:15 GMT
> 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
[quoted text clipped - 3 lines]
> 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>

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
Currently accepting short and long term contracts - on Earth.

Bjorn Abelli - 18 Nov 2005 15:35 GMT
<ameerov@gmail.com> wrote...

> I'm writing a webspider.  When a bad url is encountered
> then a MalformedURLException is thrown.  What I want to
[quoted text clipped - 8 lines]
> 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
Roedy Green - 18 Nov 2005 15:56 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.