Handling Errors <% Option Explicit On Error Resume Next Dim x x = Request.QueryString("Number1") / Request.QueryString("Number2") If Err.Number <> 0 Then If Err.Number = 11 then Response.Write "You can not divide by zero. Please try again." ElseIf Err.Number = 6 Then Response.Write "You need to provide both numbers for this text. Please try again." ElseIf Err.Number = 13 Then Response.Write "Only numbers are allowed. Please try again." Else Response.write "An unexpected error has occurred. " _ & "We are working on the problem, please try again later." End If Response.End End If Response.Write "The answer is: " & x %> Err Object <% Option Explicit On Error Resume Next Dim TheDictionary TheDictionary = Server.CreateObject("Scripting.Dictionary") If Err.Number <> 0 Then Response.Write Err.Description Response.End End If Response.Write "No problems" %> <% Option Explicit On Error Resume Next Dim conn set conn = server.createobject ("adodb.connection") conn.open "WrongDSN", "sa", "yourpassword" If Err.Number <> 0 Then Response.Write Err.Source Response.End End If Response.Write "No problems" %> Clear <% Option Explicit On Error Resume Next Dim x x = 1 / 0 Err.Clear If Err.Number <> 0 Then Response.Write Err.Description Response.End End If Response.Write "No problems" %> Error Code <% Option Explicit On Error Resume Next Response.Write FirstName("Jan") If Err.Number <> 0 Then Response.Write Err.Number & "

" Response.Write Err.Description & "

" Response.Write Err.Source & "

" End If Function FirstName (FullName) If InStr(FullName, " ") = 0 Then Err.Raise vbObjectError + 22, "MyFunction.FirstName", _ "The FullName parameter of this function must contain a space!" Else FirstName = Left(FullName, InStr(FullName, " ") - 1) End If End Function %> Error Logging <% Option Explicit On Error Resume Next Response.Write FirstName("Jan") Function FirstName (FullName) If InStr(FullName, " ") = 0 Then Err.Raise vbObjectError + 22, "MyFunction.FirstName", _ "The FullName parameter of this function must contain a space!" Else FirstName = Left(FullName, InStr(FullName, " ") - 1) End If End Function If err.number <> 0 Then Dim objFileSys Dim ObjErrorFile set objFileSys = Server.CreateObject("Scripting.FileSystemObject") set objErrorFile = objFileSys.OpenTextFile("e:\inetpub\errorfile.txt", 8, True) objErrorFile.WriteLine Err.number & " - " & Err.Description & " - " _ & Err.Source & " - " & Now & " - " & Request.ServerVariables("Script_Name") Response.Write "An error has been logged to the log file. We will address " _ & "the problem as soon as possible." End If %>