Error Handling
If an error occurs on the page but the error is not processed, the page displays an error that the user may not understand.
Can be used in ASP scripts
On Error resume next
......
If err. Number <> 0 then
Response. Write err. Description
End if
But what if an error occurs in the component? This method can capture errors, but how do you know the specific errors?
We can add error handling to the component to return errors, so that we can easily see more detailed error information and help us eliminate errors.
Use err. Raise,RaiseUsed to generate runtime errors
Open VB6 and create an ActiveX dll project. Change project name to fcom and class name to fc6
Option explicit
Public sub showerror1 ()
On Error goto errorhandle
Dim I as double
I = 1/0.
Errorhandle:
Err. Raise err. Number, Err. Source, Err. Description
End sub
'Custom error generated
Public sub showerror2 ()
Err. Raise 600, "custom error 600", "This is an error that describes your program"
End sub
OK, a component is ready. Click the menu> File> Generate the fcom. dll file.
OK. The fcom. dll file will appear in the directory.
Test
Open visual interdev6.0 and generate an ASP file
<% @ Language = VBScript %>
<HTML>
<Body>
<%
'The following sentence is very important.
On Error resume next
Set OBJ = server. Createobject ("fcom. fc6 ")
OBJ. showerror1 ()
'If there is no error processing, an error interface will be generated, which is not professional
'The range from 0 to 512 is retained as a system error; the range from 513 to 65535 can be used as a user-defined error.
'If the error is retained, the error number in the component is consistent with the error number processed on the page.
If err. Number <> 0 then
Response. Write "error message" & err. Number & err. Description
End if
Response. Write "<br>"
'If it is a user-defined error, you can handle it separately on the page.
OBJ. showerror2 ()
If err. Number <> 0 then
If err. Number = 600 then
Response. Write err. Number & err. Source & err. Description
End if
End if
%>
</Body>
</Html>
Configure the virtual directory and execute the ASP file in IE. The result is as follows:
Error message 11 divisor 0
600 self-defined error 600 this is an error that describes your own program