' create custom error values and raise error back up the call chain
intErrNumber = vbObjectError 1073 'custom error number
strErrDescription = "The file has been deleted or moved. "
strErrSource = " ReadThisFile function"
Err.Raise intErrNumber, strErrSource, strErrDescription
Exit Function
Case Else ' som other error
' raise the standard error back up the call chain
Err.Raise Err.Number, Err.Source, Err.Description
Exit Function
End Select
ReadThisFile = objFile.ReadAll ' we opened it OK, so return the content
objFile.Close
End Function
调用这个函数的代码能够使用On Error Resume Next语句,并且能捕获这个函数产生的错误。
On Error Resume Next
strContent = ReadThisFile("myfile,txt")
If Err.Number = 0 Then
Response.Write "File content is:<BR>" & strContent
Else
Response.Write "Err.Source & "<BR>" & Err.Description
End If
7.4.3 JScript错误处理
在5.0版之前,JScript的错误处理处理能力并不出色,然而在5.0版中情况改变了,JScript采用了一套和Java连同C 很类似的错误处理系统。他掌控起来尽管不像VBScript技术那样容易,但人们认为在错误处理上,JScript走在前头。
在第1章中,在讨论这两个主要脚本语言的新特点时候,已周详讨论了JScript错误处理,这里不再重复。假如阅读第1章时跳过了这部分,能够回到那里看看。
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




