ASP Component beginner and master series 6

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.