Link to home
Start Free TrialLog in
Avatar of esak2000
esak2000

asked on

foxpro error handling code for InternetExplorer.Application object

Does anyone have foxpro code for error handling and InternetExplorer.Application object?
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Once the webpage is ready and completely read then TRY CATCH structure is sufficient enough.

Or do you mean how to recognize 404 etc. errors on web pages? It is individual and depends on page design.
Avatar of esak2000
esak2000

ASKER

yes,  I would like code that catches potential errors like 404 errors or other common errors that may occur when using the InternetExplorer.Application object.

I'm familiar with try/catch, I was hoping that someone has more detailed code that I can use.

Thank you
No this is not possible. 4xx and 5xx errors are server errors and the client cannot recognize them except of the detail page contents analysis. Each server returns a valid web page and it is your responsibility to recognize the wrong contents.

So you may search the page text for "404" and "error" and some other strings but you would need to do it for each domain and language separately...

What you could do is to request some randomly named page which surely does not exist. Such a page should return an "error template" which you could use to identify real errors. Some search engines do not return 404 because they just try to search the wrong page name...
thank you for your response. How about code that catches errors  of the InternetExplorer.Application itself, like the error that would occur if there's lost internet connection or a document.form(0).item is not valid?
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want direct error messages from a web request, don't automate the IE, automate eg MsXml2.XmlHttp.

loRequest = Createobject('MsXml2.XmlHttp')
loRequest.open("GET","http://www.google.com/sdfsdg",.f.)
loRequest.send(.null.)
?loRequest.status, loRequest.statusText

Open in new window

But I think you are talking about other erros like javascript errors or such things. Then even Pavels code won't suppress them.

Bye, Olaf.

Edit:
Specifically errors, which happen when you address elements of the loaded document like in document.form(0).item can easily be catched via Try...Catch.

For example:
Local loIE, loDoc, loForm, loEx
loIE = CreateObject("internetexplorer.application")
loIE.Navigate2("about:blank")
Do While loIE.ReadyState <>4
   Doevents 
EndDo 
Try
   loDoc = loIE.Document
   ? "number of forms in the document:", loDoc.forms.length
   loForm = loDoc.forms(0).item
Catch To loEx
   ? loEx.ErrorNo, loEx.Message, loEx.LineNo
EndTry 

Open in new window


As "about:blank" by definition is a blank page, it has no html form in it, so even forms(0) does not exist. But you can detect that even without trying to access loDoc.forms(0).item, because loDoc.forms.length is then 0. Length is a typical property of any DOM collection like forms is, that contains a count of the collection items, With 0 you know there even is no first form.