Click to See Complete Forum and Search --> : Server.GetLastError() in ASP


Sathyaish
December 24th, 2003, 01:00 PM
I am just starting out on ASP and was trying to raise an Error and retrieve info about the error by making a call to the GetLastError function of the Server class, but instead what I get is the plain vanilla IE error reporting (see attachment for a picture of what my IE looks like when I run my code). Here's my code:




<%@ Language=VBScript%>

<HTML>
<%

dim objErr
Dim a

a=5/0
set objErr=Server.GetLastError()

response.write("ASPCode=" & objErr.ASPCode)
response.write("<br />")
response.write("ASPDescription=" & objErr.ASPDescription)
response.write("<br />")
response.write("Category=" & objErr.Category)
response.write("<br />")
response.write("Column=" & objErr.Column)
response.write("<br />")
response.write("Description=" & objErr.Description)
response.write("<br />")
response.write("File=" & objErr.File)
response.write("<br />")
response.write("Line=" & objErr.Line)
response.write("<br />")
response.write("Number=" & objErr.Number)
response.write("<br />")
response.write("Source=" & objErr.Source)

%>

</HTML>




Do I have to configure IIS to trap errors or something? I am using IE5 which I believe implements the ASPError object.

fmalatsi
January 16th, 2004, 01:49 AM
<%@ Language=VBScript%>

<HTML>
<%

dim objErr
Dim a

On Error Resume Next 'Just added this on your code
a=5/0
set objErr=Server.GetLastError()

response.write("ASPCode=" & objErr.ASPCode)
response.write("<br />")
response.write("ASPDescription=" & objErr.ASPDescription)
response.write("<br />")
response.write("Category=" & objErr.Category)
response.write("<br />")
response.write("Column=" & objErr.Column)
response.write("<br />")
response.write("Description=" & objErr.Description)
response.write("<br />")
response.write("File=" & objErr.File)
response.write("<br />")
response.write("Line=" & objErr.Line)
response.write("<br />")
response.write("Number=" & objErr.Number)
response.write("<br />")
response.write("Source=" & objErr.Source)

%>

</HTML>


----------------------------------------------------------------------------------
Hope it works shout if you encounter problems

Sathyaish
January 17th, 2004, 12:32 AM
Thanks. But it still doesn't populate the Error object. I mean now I simply get this output.


ASPCode=
ASPDescription=
Category=
Column=0
Description=
File=
Line=0
Number=0
Source=


Thanks for the help. Thoughts?

fmalatsi
April 26th, 2004, 10:09 AM
<%@ Language=VBScript%>

<HTML>
<%

dim objErr
Dim a
'Clear any errors before the obect is populated
Err.Clear


On Error Resume Next 'Just added this on your code
a=5/0
'You should have assigned object like this
set objErr=Err

'Supported methods that I know

Response.write("<br />")
response.write("Description=" & objErr.Description)
Response.write("<br />")
response.write("help file=" & objErr.helpfile)
Response.write("<br />")
response.write("Help Context=" & objErr.HelpContext)
Response.write("<br />")
response.write("number=" & objErr.number)
Response.write("<br />")
response.write("Raise=" & objErr.Raise)
Response.write("<br />")
response.write("Source=" & objErr.Source)



%>

</HTML>