Use err. Raise to customize error messages

Source: Internet
Author: User
Tags driver manager
I think most people are writing ASP Program You have encountered similar error messages:
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

In terms of time, this error message is not very useful to us, or the error message is not very friendly. Let's look at it in another way.

<%
Option explicit
On Error resume next

Dim Conn
Set conn = server. Createobject ("ADODB. Connection ")

'The DSN does not actually exist, so an error message is returned.
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 have defined our own error information. If you are interested, you can try it.
The output result of this error message is as follows:
Error on line-> 7
Error Source-> Etest. asp
Error desc-> connection open method failed

This seems a lot more comfortable, and I think it is always better than the original one.
Note that the error number cannot be repeated with the error number defined by the system. Therefore, 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.