0
votes

How to get error description from vb to html?I have tried below case which never works.

Code:

if err then
Response.Write " :Err Information==>>"          
%>
<HTML><table><tr><td bgcolor="#FF0000"><%=err.Description%></td></tr></table></HTML>
<%
End if
On Error Goto 0

Thanks

2

2 Answers

1
votes

What @SearchAndResQ doesn't mention is why your code is failing.

The issue here is Classic ASP will halt execution and return a HTTP 500 Internal Server to the client (depending on how the server is configured will depend how verbose the response is).

To stop execution halting when an error is encountered or manually raised using Err.Raise() use On Error Resume Next. This statement tells the VBScript runtime to jump to the next line when it encounters an error and populate the Err object.

To then capture this error check the Err.Number property to see if an error has been raised. Once you have finished use On Error Goto 0 to reset error handling to it's default state (halting execution on error).

If you want to test multiple errors between On Error Resume Next and On Error Goto 0 inside your error check (If Err.number <> 0 Then) use Err.Clear() to reset the Err object (Err.Number = 0).

'We are expecting the next statement to sometimes fail so try to trap the error.
On Error Resume Next

' << Statement here you expect to error will be skipped >>

'Check whether error occurred.
If Err.Number <> 0 Then
  'An error occurred, handle it here (display message etc).

  'Error has been handled reset the Err object.
  Call Err.Clear() 'Err.Number is now 0
End If
'Stop trapping errors
On Error Goto 0
-2
votes

Normally, the script will stop execution on an error. To see what the error is , you have to use On Error Resume Next before the line that might raise an error and then check the Err object

Example:

<%
On Error Resume Next
Dim i : i = 1/0 'division by zero should raise an error

If Err Then
'or you can check 
'If Err.number <> 0 Then
%>
    <table>
    <tr>
        <td>:Err Information==>></td>
        <td bgcolor="#FF0000"><%=err.Description%></td>
    </tr>
    </table>
<%
End If
On Error Goto 0
%>

More on Error Handling in ASP : How To Create a Custom ASP Error Handling Page