Skip to content

Incorrect exception line number reporting in ClearScript #722

Description

@Rison-Hub

When code is executed using ClearScript, if an exception occurs, the reported location cannot be accurately identified. The reported line number is usually off by one or two lines.
The following is the VBS code:

Option Explicit
Sub Main
zp.Print(zp.GetCurrentScriptName() & "Start======================================")
	Dim arr

	arr = Array(15, 88, 23, 56, 100, 3, 99)
	
	MsgBox "MaxVal:" & GetArrayMax(arr)
zp.Print(zp.GetCurrentScriptName() & "End======================================")
zp.Print("")
End Sub


'=========================

'=========================
Function GetArrayMax(arr)
    Dim i
    Dim maxValue

    If IsArray(arr) = False Then
        GetArrayMax = Empty
        Exit Function
    End If

    maxValue = arr(LBound(arr))

    For i = LBound(arr) + 1 To UBound(arr)
        If CDbl(arr(i)) > CDbl(maxValue) Then
            maxValue = arr(i)
        End If
    Next

    GetArrayMax = maxValue
End Function

The following is the C# exception handling code:

try { 
engine.Execute(scriptCode); 
} 
catch (ScriptEngineException ex)
 { 
Log.Instance.Error(ScriptGlobalList[i].ScriptName + "ErrorInfo:" + ex.ErrorDetails ); 
return; 
}

ErrorInfo Log:
06-22 19:37:33.562: ErrorInfo:没有权限: 'MsgBox'
at ([unknown]:7:1)

The error message indicates that the exception occurred on line 7, but the actual exception is on line 8.
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions