Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Err.Raise

Status
Not open for further replies.

Bakunin

Programmer
Dec 21, 2000
31
GB
Hi,
I have a question regarding raising erorrs. I have a piece of code which tries to do a HTTPRequest. If the request returns an error code I raise a specific error.

when I test this prior to complilation the err.number appears to be correct, but my err.description appears to ne over written.

When I compile and test both the err.number and err.description are overwritten.

All the work is done within one method so the err values should not be reset. Can soeone explain what is going on here??


Public Function doSearch(ByVal regMark As String, ByVal enqDate As String) As String

Dim xmlrequest As String
Dim httprequest As New MSXML2.XMLHTTP26
Dim searchString As String
Dim resultString As String

On Error GoTo searchErr


' Check parameter length
If (Len(regMark) = 0) Then
Err.Raise TRADS_EXPERIAN_ZERO_LENGTH_REGMANRK_PARAM_NUM, "Trads_POC:Experian " & TRADS_EXPERIAN_ZERO_LENGTH_REGMANRK_PARAM_DESC
End If


' Check parameter length
If (Len(enqDate) = 0) Then
Err.Raise TRADS_EXPERIAN_ZERO_LENGTH_ENQDATE_PARAM_NUM, , TRADS_EXPERIAN_ZERO_LENGTH_ENQDATE_PARAM_DESC
End If

enqDate = Format(enqDate, "yyyymmdd")

' Build the search string to submit via get
searchString = EXPERIAN_URL + enqDate + EXPERIAN_REGMARK_PARAM + regMark

' Build the request object details and submit to servlet on client
httprequest.open "GET", searchString, False
httprequest.send



' Wait for the connection to indicate that the response is ready

Do While (httprequest.readyState <> iRESPONSEREADY)
DoEvents
Loop

' Check for a valid response
If Not (httprequest.Status = EXPERIAN_RESPONSE_OK) Then
Err.Raise TRADS_CONNECTION_FAILED_ERROR_NUM, &quot;Trads_POC:Experian&quot; & TRADS_CONNECTION_FAILED_ERROR_DESC
End If

' Return result as XML string
doSearch = httprequest.responseText

exitProc:
Exit Function

searchErr:
'write the error to the log, and raise the error to the client
Call App.LogEvent(&quot;Error &quot; & Err.Number & &quot;:&quot; & Err.Description & &quot; in Experian: doSearch Method&quot;, vbLogEventTypeError)
doSearch = &quot;Error &quot; & Err.Number & &quot;:&quot; & TRADS_CONNECTION_FAILED_ERROR_DESC & &quot; in Experian: doSearch Method&quot;


End Function
 
Try clearing the error each time with Resume:

searchErr:
'write the error to the log, and raise the error to the client
Call App.LogEvent(&quot;Error &quot; & Err.Number & &quot;:&quot; & _
Err.Description & &quot; in Experian: doSearch Method&quot;, _
vbLogEventTypeError)
doSearch = &quot;Error &quot; & Err.Number & &quot;:&quot; & _
TRADS_CONNECTION_FAILED_ERROR_DESC & _
&quot; in Experian: doSearch Method&quot;
Resume ExitFunc

ExitFunc:

End Function

Paul Bent
Northwind IT Systems
 
Maybe is the way you're making the error, for example
Code:
Err.Raise TRADS_EXPERIAN_ZERO_LENGTH_REGMANRK_PARAM_NUM, &quot;Trads_POC:Experian &quot; & TRADS_EXPERIAN_ZERO_LENGTH_REGMANRK_PARAM_DESC

Remember the format of Raise is
Code:
Err.Raise ErrorNumber, ErrorSource, ErrorDescription
So if you want to call the error (i'm assuming TRADS_EXPERIAN_ZERO_LENGTH_REGMANRK_PARAM_DESC is the error description), you have to do something like:
Code:
Err.Raise TRADS_EXPERIAN_ZERO_LENGTH_REGMANRK_PARAM_NUM, &quot;&quot;, &quot;Trads_POC:Experian &quot; & TRADS_EXPERIAN_ZERO_LENGTH_REGMANRK_PARAM_DESC


Hope this helps

David.
 
Thanks David, I did spot this. What I am finding is that when I submit my XMLHTTPREquest ( which I expect to fail ) I get a sensible message back prior to compilation along the lines

Error -2146697211:Method 'send' of object 'IXMLHTTPRequest' failed in Experian: doSearch Method

Basically in my error trap I write the error to the screen and to the event log ( Nothing is written to the event log before compilaton - which i expect )

However when I compile I get

Error -2146697211:Method '~' of object '~' failed in Experian: doSearch Method

The code is

exitProc:
Exit Function

searchErr:
'write the error to the log, and return the error to the client
Call App.LogEvent(&quot;Error &quot; & Err.Number & &quot;:&quot; & Err.Description & &quot; in Experian: doSearch Method&quot;, vbLogEventTypeError)
doSearch = &quot;Error &quot; & Err.Number & &quot;:&quot; & Err.Description & &quot; in Experian: doSearch Method&quot;

Resume exitProc


 
It seems the problem is not the Raise method, i search a little and it seems the problem is get because of the references in the project, maybe the dll you are using for the http object (MSXML2.XMLHTTP26).
I'm not sure the right answer because i never get this kind of error before.
You can check the thread222-512387, and see if that helps. Sorry I cant help you more.

David.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top