ASP component primary entry and exquisite series

zhaozj2021-02-16  99

Error handling

If the page is wrong, there is no handling of the error, then the page will display an error that the user may not understand.

Can be used in the ASP script

ON Error ResMe next

......

IF Err.Number <> 0 THEN

Response.write Err.Description

END IF

But if the component is wrong? This method can capture errors, but how specific errors know?

We can add an error handling in the component to return an error, which can easily see more detailed error information, which helps us to troubleshoot errors.

Using Err.raise, Raise is used to generate runtime errors

Open VB6, create a new ActiveX DLL project. The engineering name is modified to FCOM, and the class name is modified to FC6

Option expedition

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

'Generate custom errors

Public Sub showerror2 ()

Err.raise 600, "I have a defined error 600", "This is the error describing your own program"

End Sub

OK, a component is written, click on the menu -> File -> Generate the FCOM.dll file

Determine, there will be an FCOM.dll file in the directory.

test

Open Visual InterDev6.0 to generate an ASP file

<% @ Language = VBScript%>

<%

'This sentence is very important

ON Error ResMe next

Set obj = server.createObject ("fcom.fc6")

Obj.showerror1 ()

'If there is no error handling, it will generate an error interface, it is very unprofessional.

'The range from 0-512 is preserved as a system error; the range from 513-65535 can be used as a user-defined error.

'If you keep an error, the error number of the error number and page processing in the component is consistent.

IF Err.Number <> 0 THEN

Response.write "Error Message" & Err.Number & Err.Description

END IF

Response.write "
"

'If it is a user-defined error, you can process 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

%>

Configure a virtual directory, perform this ASP file in IE, resulting in the following:

Error message

11

Due to zero

600

Berses defined errors

600

This is a mistake to describe your own program.

转载请注明原文地址:https://www.9cbs.com/read-10503.html

New Post(0)