Menu

Catching Error's

Help
Anonymous
2004-01-16
2004-01-16
  • Anonymous

    Anonymous - 2004-01-16

    hi,
    I am using the parser to extract links from HTML pages. It is a part of my application. The problem is that for some URLs like 'http://news.google.com', which cannot be fetched, the parser throws an error and exits. This makes my appilcation stop. Can anyone suggest a way to catch and ignore this error rather than stopping the application.
    Thank you.

     
    • Derrick Oswald

      Derrick Oswald - 2004-01-16

      That URL issues a 403 - forbidden, with the simple GET that the parser uses. Catch the IOException it's throwing:

      try
      {
         ...do the parse...
      }
      catch (IOException ioe)
      {
         ioe.printStackTrace();
      }

      A sophisticated application would use parser.setConnection() with a valid connection (whatever it takes for the URL not to issue a 403). See http://htmlparser.sourceforge.net/wiki/index.php/PostOperation for an example using POST, but the same technique applies to exotic GET requests.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.