views:

49

answers:

1

I've begun using ASPUnit to unit test my classic ASP code. This is all good and I'm happy. The only problem is with the error messages it displays when a test generates a runtime error. For example, if I've not defined a variable somewhere in my function I get the error:

Microsoft VBScript runtime error (500): Variable is undefined

What would be more useful is if it could tell me which file/line the error occurred on. I know that I can get this information from the ASPError object which is returned by the Server.GetLastError() and elsewhere in my project I have a custom 500 error page which makes use of this method to automatically report crashes to Fogbugz. However when I try to access Server.GetLastError anywhere else the information returned is blank. For example, the following code will output zero rather than the expected 4.

<%
Option Explicit
On Error Resume Next
aVariable = "hello"
Dim errObj : Set errObj = Server.GetLastError()
Response.Write errObj.Line
%>

Is this the correct way to access ASPError or is it only possible on custom error pages? Is there a better way to get error messages reported within ASPUnit?

+1  A: 

To the best of my knowledge the ASPError object does not get populated until your current page finished processing. Its meant to only be used on the 500 error page only. So theory is when you get an error if you've set up your 500 page then IIS will do an internal redirect to that page to allow you to at least record the error. Then and only then is the ASPError object available. I've had crazy ideas of using a xmlhttprequest to try to grab the page but thats just not the way it works.

In short there is not much you can do to get that error message details that you want.

Using JScript server side you can use try catch's which give you access to a exception object but even thats not much good to you, no line numbers or anything. Rubbish.

Pete Duncanson
Boo. That's what I was afraid of. Thanks for taking the time to reply.
jammus