Using an error....

Results 1 to 2 of 2

Thread: Using an error....

  1. #1
    Join Date
    Dec 1969

    Default Using an error....

    I was wondering if it is possible to use an error. I want to use the error "ADODB.Recordset error &#039 800a0bcd&#039" to output an line like: "the requested directory is not availible". The error is of no concern to me, i know why it is there, but i do not want it to be seen as output. Can anybody give me a clue?<BR>Thanks..

  2. #2 Guest

    Default RE: Using an error....

    You just add a line before where you want to trap errors:<BR><BR>&#060;%on error resume next%&#062;<BR><BR>Then at the point where you want to trap errors you then add:<BR><BR>&#060;%If err=76 then response.write %&#062;<BR><BR>If you want turn off error trapping at some other point you add the line:<BR>&#060;%On Error Goto 0%&#062;<BR><BR>NOTE: Many would consider the use of the error trap in this way the LAZY way. In fact the filesystem object includes methods for checking the existence of files and folders. Where the language or environment provides a means for the programmer to check a condition he should use it instead of on error resume.<BR><BR>&#060;%<BR>set fso=server.CreateObject("Scripting.FileSystemObjec t")<BR>if not fso.FolderExists(Server.MapPath("/xxx")) then Response.Write "the requested directory is not availible"<BR>%&#062;<BR><BR>The reason why it is bad practice to rely solely on "On Error Resume", is that from the point where you use it, you script becomes an out-of-control runaway train. It will not stop for any error and you may not notice errors that are critical to your application.<BR><BR>Therefore if you use it, you need to identify every point where an error could occur and include error checking code. So if you have to go to the trouble of checking that your runaway code is not out of control, why not do it the right way and use object methods and built-in language features?<BR><BR>There is of course an exception: In security-conscious situations, system error messages may reveal critical info such as the server path to you database, that hackers could use to attack your system. Or an non-critical error might prevent an on-line shopper from being able to complete his purchases.In such cases you should thoroughly test your code and include error-avoiding code. Then Prior to release you should add the "On Error Resume" near the top of your code. This means that on your development version all errors will be exposed, but on the production system your program will never expose an unexpected error to the end user.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts