Link:http://output.to/sideway/default.asp?qno=180500011 Script, Scripting Language, VBScript elements, Server-Side VBScript Err Object
VBScript Err ObjectErr Object is a build-in VBScript Object for storing run-time error in form of an Object.
Err Objectlast updated 12/10/2017is to provide simple intrinsic global support for containing information about run-time errors.
Remarks- Contains information about run-time errors. Accepts the Raise and Clear methods for generating and clearing run-time errors.
- The Err Object is an intrinsic object with global scope. In other words, no new instance of Err Object reference is needed to be created.
- The properties of the Err object can be set either by the error generator, for example Visual Basic, VBScript, and an Automation object, or by code using Raise Method.
- The default property of the Err object is Number. Err.Number contains an integer and can be used by an Automation object to return an SCODE.
- When a run-time error occurs, the properties of the Err object are filled with information that uniquely identifies the error and information that can be used to handle it. Besides, the Raise method can be used to generate a run-time error in the code explicitly.
- The Err Object's properties are reset to zero or zero-length strings ("") after an On Error Resume Next statement.Besides, the Clear method can be used to explicitly reset the properties of Err Object.
Requirement1 Err Methodslast updated 12/10/2017Two Methods are predefined for the Err Object, namely, Clear Method, and Raise Method. Dot notation is used to access the available Method for an Err Object, for example, Err.methodname.
SyntaxErr.Clear Err.Raise(number[, source, description, helpfile, helpcontext]) Err Propertieslast updated 12/10/2017Five Properties are predefined for the Err Object, namely, Description Property, HelpContext Property, HelpFile Property, Number Property, and Source Property. Dot notation is used to access the available Property for an Err Object, for example, Err.propertyname. The Number Property is the default Property of an Err Object.
SyntaxErr.Description [= stringexpression] Err.HelpContext [= contextID] Err.HelpFile [= contextID] Err.Number [= errornumber] Err.Source [= stringexpression] ExamplesExamples of Dictionary Object ASP VbScript Command:<script runat="server" language="VBScript">
Dim vars,strs,cmda:varx=1
cmda=array("f","g","h")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0 Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&")," "," "),"""","""),"<","<"),">",">"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0 Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function
vars="On Error Resume Next: f=Err.Number:g=Err.Description: h=Err.Source:Err.Clear":Execute vars:dsp_x
vars="On Error Resume Next:Err.Raise(32811): f=Err.Number:g=Err.Description: h=Err.Source:Err.Clear":Execute vars:dsp_x
vars="On Error Resume Next: f=Err.Number:g=Err.Description: h=Err.Source:Err.Clear":Execute vars:dsp_x
</script>
HTML Web Page In-line Output:Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp varsf, TypeNameg, TypeNameh, TypeNameOn Error Resume Next: f=Err.Number:g=Err.Description: h=Err.Source:Err.Clear[0], Long[], String[], StringOn Error Resume Next:Err.Raise(32811): f=Err.Number:g=Err.Description: h=Err.Source:Err.Clear[32811], Long[Element not found], String[Microsoft VBScript runtime error], StringOn Error Resume Next: f=Err.Number:g=Err.Description: h=Err.Source:Err.Clear[0], Long[], String[], String
|
|