Click to See Complete Forum and Search --> : onError Help!!!


Will192
02-10-2003, 02:40 PM
I have my error checking setup in Javascript. If I get an ASP error, the error checker doesn't catch it. What do I have to do to get error capture at the ASP level?

Will192

Ribeyed
02-10-2003, 05:15 PM
hi,
2 ways you can do this, first remove this line:

onerror resume next

or add in this line:

set objError = Server.GetLastError()
response.write objError.Description

Hope this helps

Will192
02-11-2003, 10:17 AM
I understand taking out the one line. The other two lines don't seem to do anything that has to do with capturing the error condition. Thanks for the reply, but please explain.

Will192

Ribeyed
02-11-2003, 10:30 AM
Hi,
<%
onerror resume next
set objError = Server.GetLastError()
response.write objError.Description
%>

The GetLastError method allows you to retrieve information about the last error that occured in a script and proces it accordinaly. This method is called from within the script, which is invoked automatically when an error occurs. The GetLastError method returns an ASPError object, which contains error information: the error's number, its description, the script name, line number where it occurred, and so on. You can use the properties of the ASPError object to take some action from within your script or at least display a descriptive error message to the viewer.
The objError is and ASPError object variable that exposes a number of properties with information about the last error. To find out the description of the error you use the Description property of the objError variable, ok?

Will192
02-11-2003, 11:24 AM
I understand that the GetLastError will return the last error information.

What I need is the ASP equilivant of window.onerror statement in Javascript. I need to be able to set which procedure/function is called when an ASP error occurs.

The GetLastError function will be useful in the procedure/function that is called when I get an ASP error. I just need to be able to set what function is called.

Thanks again for your quick response.

Will192

Ribeyed
02-11-2003, 11:55 AM
hi,
there is another property of the ASPError objetc you can try:
response.write objError.Source
This would display the statement that cause the error.

Will192
02-11-2003, 01:54 PM
Thanks for the help, but it doesn't solve my problem.

Here is what I need:

I need a statement that directs my program to to another function/procedure when an error occurs.

The information that you are giving me is helpful. Your suggestion only gives me information on what do to in my error handling procedure, not how to set my procedure/function to what is called when an error occurs.

I need to be able to call a procedure when an error occurs.

Thanks for your quick reply.

Will192

Ribeyed
02-11-2003, 03:39 PM
hi,
ok no problem can you post the code you have so far?

Scriptage
02-11-2003, 04:52 PM
I don't know how closely vbscript and visual basic are related but you can try this.

In visual basic when you have a sub routine you can define the code to run in an error by writing this:

sub some_subroutine

on Error GoTo errorHandler

your code here

Exit Sub

errorHandler:

code to run on error goes here

end sub

This is the best way to handle errors in vb...
I can't see vbscript being much different.

Regards
Scriptage

Will192
02-12-2003, 02:26 PM
Ok guys, here is my Javascript code. What I need to do in ASP is trap the error. I know how to pull the error information once I trap it. I just need to figure out how to trap the error in ASP.


// JavaScript Source for vperror.js
// written by Will Summers

function Werror(message, url, line) {
err='';
for (var i = 0; i < message.length; i++) { if (message.charAt(i)!="'") { err=err+message.charAt(i); } }
var newurl = 'vperror.asp?errormessage='+err+'&errorurl='+url+'&errorline='+line+'&errorSuitsID=none'+fnKey;
window.location=newurl;
}

window.onError=Werror;


In another file I have this line to setup the error checking:

<SCRIPT LANGUAGE='JavaScript' SRC='vperror.js' ></SCRIPT>


This method will trap HTML & Javascript errors, what I need is to trap the ASP errors. Thanks in advance for any help any of you can give.

Will

russell
02-18-2003, 12:15 AM
In ASP / VbScript

<%

On Error Resume Next

doSomethingThatMightRaiseAnError

If err.number <> 0 Then
' We Trapped an error!!!

With Response
.Write Err.Number & "<br>"
.Write Err.Description & "<br>"
End With

End If

Hopefully, you can think of a more elegant way to handle the error than just write it to the screen, but there is your standard VbScript error trapping routine.

-- rb

Will192
02-18-2003, 12:30 PM
I'm pretty sure that this code will only trap an error on the front end.

I need ASP code that will trap an error that happens on the backend. I need to trap errors such as a misspelled table name.

Thanks for the reply, I will try it out and see if it helps with backend errors.

Will192

russell
02-18-2003, 08:25 PM
That will trap errors on the back-end.

On Error Resume Next

sql = "SELECT * FROM BadTableName"
Set rs = cn.Execute(sql)
...

If Err.Number <> 0 Then
' handle the rror
end if

Will192
02-19-2003, 09:09 AM
That would explain the responses that I have been getting. Thanks for clearing it up.

Will192