ASP components introductory and proficient series VI

Source: Internet
Author: User
Error handling

If the page goes wrong without handling the error, the page displays an error that a user may not be able to read.

In ASP scripts, you can use the

On Error Resume Next

......

If Err.number<>0 Then

Response.Write Err.Description

End If

But what if there is an error in the component? This method can catch errors, but how do you know the exact error?

We can add error handling to the component to return errors so that we can easily see more detailed error messages and help us to troubleshoot the error.



Using Err.Raise, Raise is used to generate Run-time errors

Open VB6 and create a new ActiveX DLL project. Project name modified to fcom, class name modified 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

' Generate custom errors

Public Sub Showerror2 ()

Err.Raise 600, "your own definition of error 600", "This is the error of describing your own program."

End Sub



OK, a component is written, click the menu-> file-> generate FCom.dll file

OK, there will be a FCom.dll file in the directory



Test

Turn on visual interdev6.0 to 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 handling, it will produce an error interface, very unprofessional

' From 0–512 to a system error, from a 513–65535 range can be used as a user-defined error.

' If the error is reserved, the error number in the component is consistent with the error number of the page processing

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, it can be handled separately in 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, in IE to execute this ASP file, the results are as follows:



Error message 11 divisor is zero
600 your own definition of error 600 This is the error of describing 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.