Customizing error messages with Err.Raise

Source: Internet
Author: User
Tags driver manager odbc
Error I think most people have encountered similar error messages when they write ASP programs:
Error Number->-2147467259
Error Source-> Microsoft OLE DB Provider for ODBC Drivers
Error Desc-> [microsoft][odbc Driver Manager] Data source name not found and no default Driver

But in time, this error message is not very useful to us, or the wrong message is not very friendly, let us look at the different ways to see.

<%
Option Explicit
On Error Resume Next

Dim Conn
Set Conn = Server.CreateObject ("ADODB. Connection ")

' This DSN does not actually exist, so return the error message
Conn.Open "Foo"

If Err.Number <> 0 Then
Err.Clear
Err.Raise vbObjectError + 7, _
"Etest.asp", "Connection Open method Failed"
End If
If Err. Number <> 0 Then
Response.Write ("Error on line->" & Err.number-vbobjecterror)
Response.Write ("<br>error Source->" & Err.Source)
Response.Write ("<br>error Desc->" & Err.Description)
Err.Clear
End If
%>

In this way, we define the error message ourselves, interested friends can try
The following is the output of the error message:
Error on line-> 7
Error Source-> etest.asp
Error Desc-> Connection Open method Failed

It looks more comfortable, and I think it's better than the original.
Note that defining the error number cannot be repeated with the system's previously defined error number, so a constant is added here.

:)



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.