包含導(dǎo)致錯誤的源代碼行。
Object.SourceText
SourceText 屬性返回一個字符串。
不是任何情況下都可以獲得源文本。如果得不到源文本,SourceText 屬性將返回一個空字符串。
下面的代碼演示 WshRemoteError 對象如何展示導(dǎo)致錯誤的源代碼行。
Dim Controller, RemoteScript
Set Controller = WScript.CreateObject("WSHController")
Set RemoteScript = Controller.CreateScript("test.js", "remoteserver")
WScript.ConnectObject RemoteScript, "remote_"
RemoteScript.Execute
Do While RemoteScript.Status <> 2
WScript.Sleep 100
Loop
Sub remote_Error
Dim theError
Set theError = RemoteScript.Error
WScript.Echo "Error - Line: " & theError.Line & ", Char: " & theError.Character & vbCrLf & "Description: " & theError.Description & vbCrLf & "Source Text: " & theError.SourceText
WScript.Quit -1
End Sub
var Controller = WScript.CreateObject("WSHController");
var RemoteScript = Controller.CreateScript("test.js", "remoteserver");
WScript.ConnectObject(RemoteScript, "remote_");
RemoteScript.Execute();
while (RemoteScript.Status != 2) {
WScript.Sleep(100);
}
function remote_Error()
{
var theError = RemoteScript.Error;
WScript.Echo("Error - Line: " + theError.Line + ", Char: " + theError.Character + "\nDescription: " + theError.Description + "\nSource Text: "_+ theError.SourceText
);
WScript.Quit(-1);
}
WshRemote 對象 | WshRemoteError 對象 | Description 屬性 | Line 屬性 | Character 屬性| Number 屬性 | Source 屬性