共用方式為


SourceText Property

Contains the line of source code that caused an error.

                      Object.SourceText

Arguments

  • Object
    WshRemoteError object.

Remarks

The SourceText property returns a string.

It is not always possible to obtain the source text. If that is the case, the SourceText property returns an empty string.

Example

The following JScript code demonstrates how the WshRemoteError object exposes the line of source code that caused an error.

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);
}

Applies To:

WshRemoteError Object

See Also

Reference

WshRemote Object

Description Property (WshRemoteError)

Line Property (WScript)

Character Property

Number Property (Windows Script Host)

Source Property (Windows Script Host)