仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2598|回复: 20
打印 上一主题 下一主题

[学习教程] ASP网站制作之Generating Sensible Error Messages U...

[复制链接]
谁可相欹 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:39:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
国内有些大的CRM厂商的ASP就写得不错.无论是概念还是它里面用JAVASCRIPT的能力.并不是说现在的程序员用了ASP.NET来写程序就可以说自己高档了error   Okay, I'll admit it, if there's one area where my ASP scripts are lacking: it's in the area of error checking. I've looked at the Err object included with VBScript but have been really frustrated with it's seemingly lack of information. (For more information on the Err object be sure to read: Error Handling in ASP!) Consider this snippet of code:

<%
  Option Explicit

  Dim Conn
  Dim strSQL

  Set Conn = Server.CreateObject("ADODB.Connection")
  'this DSN does not exist
  Conn.Open "foo"
  '...




If you run the above script (without having a DSN named foo created) you'll get the following error:


Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/dmsms/etest.asp, line 6

Fine, I can deal with that. While the error message is anything but pretty or profoundly descriptive, I do know that I need to fix something that's wrong on line 6 of the script. So I'll load it into the editor, fix it and then try running it again. If needed I'll repeat this cycle until I have a script that works.

Now consider a script like this one that has Error checking turned on:

<%
  Option Explicit

  On Error Resume Next

  Dim Conn
  Dim strSQL

  Set Conn = Server.CreateObject("ADODB.Connection")
  'this DSN does not exist
  Conn.Open "foo"

'... more code ...

  If Err.Number <> 0 then
    Response.Write("Error Number -> " & Err.Number)
    Response.write("<BR>Error Source -> " & Err.Source)
    Response.Write("<BR>Error Desc   -> " & Err.Description)
    Err.Clear
  End If
%>




Viewing the above script through your browser will produce the following output:


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 specified
To me this information is less useful than the default error message. At least with the default error message I know the line on which the error originated. Recently I was having yet another look at the Err object and I stumbled upon something that I've overlooked many times in the past. You can raise your own errors!

The Err object contains a Raise method that does exactly this. The Raise method has the following syntax:

object.Raise(number, source, description, helpfile, helpcontext)  


The technical docs for the Raise method can be seen here. A quick note: when raising a custom error, the error number should be a custom error number plus the constant vbObjectError, to make sure that the error number you choose doesn't equal an already predefined error number (we'll see an example of this in the code below).

An example of using the Raise object to generate our own custom error (with a more descriptive message and the line number) can be seen below:

1: <%
2:    Option Explicit
3:    On Error Resume Next
4:
5:    Dim Conn
6:    Set Conn = Server.CreateObject("ADODB.Connection")
7:
8:    'this DSN does not exist
9:    Conn.Open "foo"
10:
11:   If Err.Number <> 0 then
12:     Err.Clear
13:     Err.Raise vbObjectError + 7, _
14:               "etest.asp", "Connection Open Method Failed"
15:   End If
16:   If err.Number <> 0 then   
17:     Response.Write("Error On line    -> " & Err.Number - vbObjectError)
18:     Response.write("<BR>Error Source -> " & Err.Source)
19:     Response.Write("<BR>Error Desc   -> " & Err.Description)
20:&nbsp</p>  asp对于服务器的要求较高,一般的服务器如果访问量一大就垮了,不得不重启。
莫相离 该用户已被删除
沙发
发表于 2015-2-4 04:50:11 | 只看该作者
在平时的学习过程中要注意现学现用,注重运用,在掌握了一定的基础知识后,我们可以尝试做一些网页,也许在开始的时候我们可能会遇到很多问题,比如说如何很好的构建基本框架。
若相依 该用户已被删除
板凳
发表于 2015-2-7 07:41:14 | 只看该作者
代码逻辑混乱,难于管理:由于ASP是脚本语言混合html编程,所以你很难看清代码的逻辑关系,并且随着程序的复杂性增加,使得代码的管理十分困难,甚至超出一个程序员所能达到的管理能力,从而造成出错或这样那样的问题。
再见西城 该用户已被删除
地板
发表于 2015-2-17 17:46:23 | 只看该作者
运用经典的例子。并且自己可以用他来实现一些简单的系统。如果可以对他进行进一步的修改,找出你觉得可以提高性能的地方,加上自己的设计,那就更上一个层次了,也就会真正地感到有所收获。
若天明 该用户已被删除
5#
发表于 2015-3-5 21:37:21 | 只看该作者
ASP的语言不仅仅只是命令格式差不多,而是包含在<%%>之内的命令完全就是VB语法。虽然ASP也是做为单独的一个技术来提出的,但他就是完全继承了VB所有的功能。
兰色精灵 该用户已被删除
6#
发表于 2015-3-10 10:18:47 | 只看该作者
封装性使得代码逻辑清晰,易于管理,并且应用到ASP.Net上就可以使业务逻辑和Html页面分离,这样无论页面原型如何改变,业务逻辑代码都不必做任何改动;继承性和多态性使得代码的可重用性大大提高。
老尸 该用户已被删除
7#
发表于 2015-3-17 06:10:34 | 只看该作者
ASP也是这几种脚本语言中最简单易学的开发语言。但ASP也是这几种语言中唯一的一个不能很好支持跨平台的语言。  因为ASP脚本语言非常简单,因此其代码也简单易懂,结合HTML代码,可快速地完成网站的应用程序。
飘灵儿 该用户已被删除
8#
发表于 2015-3-23 22:43:04 | 只看该作者
哪些内置对象是可以跳过的,或者哪些属性和方法是用不到的?
金色的骷髅 该用户已被删除
9#
发表于 2015-4-8 15:50:36 | 只看该作者
还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。
分手快乐 该用户已被删除
10#
发表于 2015-4-9 03:52:46 | 只看该作者
接下来就不能纸上谈兵了,最好的方法其实是实践。实践,只能算是让你掌握语言特性用的。而提倡做实际的Project也不是太好,因为你还没有熟练的能力去综合各种技术,这样只能使你自己越来越迷糊。
简单生活 该用户已被删除
11#
发表于 2015-4-12 13:55:47 | 只看该作者
代码逻辑混乱,难于管理:由于ASP是脚本语言混合html编程,所以你很难看清代码的逻辑关系,并且随着程序的复杂性增加,使得代码的管理十分困难,甚至超出一个程序员所能达到的管理能力,从而造成出错或这样那样的问题。
变相怪杰 该用户已被删除
12#
发表于 2015-4-17 17:47:37 | 只看该作者
他的语法和设计思路和VB完全相同,导致很多ASP的书都留一句“相关内容请参考VB的相关教材....”更糟糕的是,相当多的ASP教程混合了Javascript,VBscript等等脚本语言,搞的初学者。
谁可相欹 该用户已被删除
13#
 楼主| 发表于 2015-5-1 03:43:06 | 只看该作者
弱类型造成潜在的出错可能:尽管弱数据类型的编程语言使用起来回方便一些,但相对于它所造成的出错几率是远远得不偿失的。
不帅 该用户已被删除
14#
发表于 2015-5-1 20:23:13 | 只看该作者
掌握asp的特性而且一定要知道为什么。
海妖 该用户已被删除
15#
发表于 2015-5-3 11:38:43 | 只看该作者
封装性使得代码逻辑清晰,易于管理,并且应用到ASP.Net上就可以使业务逻辑和Html页面分离,这样无论页面原型如何改变,业务逻辑代码都不必做任何改动;继承性和多态性使得代码的可重用性大大提高。
飘飘悠悠 该用户已被删除
16#
发表于 2015-6-6 21:10:01 | 只看该作者
如何学好ASP,以前也有人问过,把回答给你转过来看看能否对你有帮助:
活着的死人 该用户已被删除
17#
发表于 2015-6-9 07:42:00 | 只看该作者
交流是必要的,不管是生活还是学习我们都要试着去交流,通过交流我们可以学到很多我们自己本身所没有的知识,可以分享别人的经验甚至经历。
柔情似水 该用户已被删除
18#
发表于 2015-6-14 08:47:35 | 只看该作者
另外因为asp需要使用组件,所以了解一点组件的知识(ADODB也是组件)
山那边是海 该用户已被删除
19#
发表于 2015-6-20 04:05:19 | 只看该作者
它可通过内置的组件实现更强大的功能,如使用A-DO可以轻松地访问数据库。
冷月葬花魂 该用户已被删除
20#
发表于 2015-7-7 15:01:04 | 只看该作者
交流是必要的,不管是生活还是学习我们都要试着去交流,通过交流我们可以学到很多我们自己本身所没有的知识,可以分享别人的经验甚至经历。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-7 09:52

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表