处理Asp中的错误

2016-01-29 19:36 3 1 收藏

处理Asp中的错误,处理Asp中的错误

【 tulaoshi.com - ASP 】

       处理Asp中的错误
  
  You just finished your ASP application in time, barely making the dealine! As you upload the final version to the webserver, you receive an email from your supervisor indicating that he''s ready for your demo. You confidently stride into his office and give him instructions on accesses the application through the Intranet.
  
  Your boss comes to the first page, and is asked to enter his name. You''ve created a slick, customized feel to the site, recording the user and his or her preferences in a database. Your boss types in his name, "The Pointy Haired Boss," and hits the submit button. Instead of being taken to the next page, he sees the following text pop up on the screen:
  
  Microsoft OLE DB Provider for ODBC Drivers error '' 80004005'' [Microsoft][ODBC Access 97 ODBC driver Driver] syntax wrong near ''
  
  Please note that I just made this error message up, so, please, no emails asking about how one gets this error by entering his name!
  
  You get one of those looks from your boss, a look that says, "I hope you weren''t expecting a positive performance review."
  
  There''s nothing worse to an end user than to see those dreaded ADO errors. They are misformatted, cryptic, and leave the user wondering what they are suppose to do. Your average end user doesn''t know ODBC from OLE. So how can you prevent these nasty error messages?
  
  First you must insert at the top of your ASP page:
  
  
  <% On Error Resume Next %>
  This will tell ASP to just skip over any errors, instead of halting execution and printing out a nasty error message. You may be tempted to leave it at this, although if you do, and errors occur, your users won''t be aware of them. They will think their information was correctly saved, when in actuality it wasn''t due to an ADO error.
  
  What, then, do we want to do if there is an error? Well, the idea situation would be to let the end user know that an error had occurred and will be worked on, and automatically email technical support with the ADO error messages. So that is what we will do!
  
  The question now is how to we "trap" errors? Well, after any ADO call that accesses the database, we will want to put the following lines:
  
  
  
  If Err.number <> 0 then
   TrapError Err.description
  End If
  
  You will want to put this after all ADO calls that communicate directly with the database. This includes ConnectionObject.Open, ConnectionObject.Execute, and RecordsetObject.Open. Now, you may be wondering where the sub TrapError is defined: we''re about to do that. Create a file called ErrorHandler.asp and put it in your /include or /scripts directory. In ErrorHandler.asp, we will have the following subs:
  
  
  TrapError
  ProcessErrors
  Let''s look at the code for ErrorHandler.asp:
  
  
  
  <%
  Dim strErrorMessage
  Dim bolErrors
  
  ''Initialize variables
  strErrorMessage = "" ''The error messages for tech. support
  bolErrors = False ''Have we found any errors yet?
  
  ''Now our two subs
  sub TrapError(strError)
   bolErrors = True ''Egad, we''ve found an error!
  
   strErrorMessage = strErrorMessage & strError & ", "
  end sub
  
  
  
  ''If there are any errors, this function will email tech. support
  sub ProcessErrors()
   if bo

来源:https://www.tulaoshi.com/n/20160129/1509754.html

延伸阅读
标签: SQLServer
大多数迭代语言编译器都有内置的错误处理程序(例如,TRY…CATCH语句),开发者们在设计代码的时候可以利用它们。虽然SQL Server 2000的开发者不能够像迭代语言的开发者那样利用内置的工具,但是他们可以用系统变量@@ERROR来设计自己有效的错误处理工具。 引入事务 为了能够掌握在SQL Server 2000中错误处理是如何工作的,你必须首先要理...
标签: ASP
        以国内最流行ASP为例,我不知道有多少人会在写代码时想到“容错”这个概念,实际上当我遇到这种事时,也是不了了之。为什么呢,想想最初的意思是认为写如下代码就能容错了,见示例1-1。 <%@ Language=VBScript % <%option explicit% <% '出错过滤 on error resu...
标签: ASP
  有的网友总是把出错页面一个一个做好后,在其它的ASP页面中调用出错的页面。比方在一个登陆页面中一般会有两个出错信息,一个是最常见的密码出错,还有一个是用户名未注册。一般的网友会做两个页面来处理,一个页面显示:出错,密码出错!,别一个面面显示:出错,用户名未注册。     其实你只要做一个页面,就可以...
----在VB软件开发中,错误信息的捕获及处理是非常重要的部分。有些错误在编译时即可发现、排除。但还有一些错误是在软件运行时由于用户错误的输入等方面的原因而产生的,这就需要软件开发者在软件设计和开发时注意处理这方面的错误。VB在捕获及处理错误信息方面有两个重要的函数。一个是ERROR,该函数捕获错误信息。另一个是ERR,该函数捕获、返...
标签: ASP
下面是虚机维护中,经常碰到的一些ASP程序中的数据库调用的错误,现收集整理如下: 不能打开注册表关键字(8007000e) Microsoft OLE DB Provider for ODBC Drivers 错误 '8007000e' [Microsoft][ODBC Microsoft Access Driver]常见错误 不能打开注册表关键字 'Temporary (volatile) Jet DSN for process 0x11b4 Thread 0x1a4...

经验教程

944

收藏

51
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部