wizards/source/scriptforge/SF_Exception.xba | 24 +++++++++++++++++++++++- wizards/source/scriptforge/SF_Services.xba | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-)
New commits: commit 4591b440697758d0a6b347f1c3ea9fdfa61ad73f Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Thu Aug 8 18:34:36 2024 +0200 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Fri Aug 9 14:02:33 2024 +0200 ScriptForge Revisit error handling in user scripts In Basic, any On Error ... statement resets the Err, Erl, Error$ system variables. Most ScriptForge public interfaces contain such a statement. To enhance error handling in user scripts, the usual interfaces expected in error handling routines start (before the On Error statement) with the capture of the actual system error status. The concerned interfaces are: - all methods in the Exception service - the CreateScriptService() method to create the Exception service The functionality is particularly useful to manage user script errors in events. Only Basic scripts are concerned. Change-Id: I602311ceedcafddd46481bdd9cc20d9946db3186 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171649 Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> Tested-by: Jenkins diff --git a/wizards/source/scriptforge/SF_Exception.xba b/wizards/source/scriptforge/SF_Exception.xba index 4b0fdb8d5eb1..f15941f70f21 100644 --- a/wizards/source/scriptforge/SF_Exception.xba +++ b/wizards/source/scriptforge/SF_Exception.xba @@ -121,6 +121,9 @@ Const BASEFORMNOTFOUNDERROR = "BASEFORMNOTFOUNDERROR" Const SUBFORMNOTFOUNDERROR = "SUBFORMNOTFOUNDERROR" Const FORMCONTROLTYPEERROR = "FORMCONTROLTYPEERROR" +' SF_Writer +Const WRITERRANGEERROR = "WRITERRANGEERROR" + ' SF_Dialog Const DIALOGNOTFOUNDERROR = "DIALOGNOTFOUNDERROR" Const DIALOGDEADERROR = "DIALOGDEADERROR" @@ -282,6 +285,8 @@ Dim oNonModalBtn As Object ' Non modal close button Const cstThisSub = "Exception.Console" Const cstSubArgs = "[Modal=True]" + ' Save Err, Erl, .. values before any On Error ... statement + SF_Exception._CaptureSystemError() If SF_Utils._ErrorHandling() Then On Local Error GoTo Finally ' Never interrupt processing Check: @@ -339,6 +344,8 @@ Dim lConsole As Long ' UBound of ConsoleLines Const cstThisSub = "Exception.ConsoleClear" Const cstSubArgs = "[Keep=0]" + ' Save Err, Erl, .. values before any On Error ... statement + SF_Exception._CaptureSystemError() If SF_Utils._ErrorHandling() Then On Local Error GoTo Finally ' Never interrupt processing Check: @@ -382,6 +389,8 @@ Dim sLine As String ' A single line Const cstThisSub = "Exception.ConsoleToFile" Const cstSubArgs = "FileName" + ' Save Err, Erl, .. values before any On Error ... statement + SF_Exception._CaptureSystemError() If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch bExport = False @@ -434,6 +443,8 @@ Const cstMaxLength = 1024 Const cstThisSub = "Exception.DebugDisplay" Const cstSubArgs = "Arg0, [Arg1, ...]" + ' Save Err, Erl, .. values before any On Error ... statement + SF_Exception._CaptureSystemError() If SF_Utils._ErrorHandling() Then On Local Error Goto Finally ' Never interrupt processing SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Try: @@ -475,6 +486,8 @@ Const cstMaxLength = 1024 Const cstThisSub = "Exception.DebugPrint" Const cstSubArgs = "Arg0, [Arg1, ...]" + ' Save Err, Erl, .. values before any On Error ... statement + SF_Exception._CaptureSystemError() If SF_Utils._ErrorHandling() Then On Local Error Goto Finally ' Never interrupt processing SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Try: @@ -577,6 +590,8 @@ Const cstPyHelper = "$" & "_SF_Exception__PythonPrint" Const cstThisSub = "Exception.PythonPrint" Const cstSubArgs = "Arg0, [Arg1, ...]" + ' Save Err, Erl, .. values before any On Error ... statement + SF_Exception._CaptureSystemError() If SF_Utils._ErrorHandling() Then On Local Error Goto Finally ' Never interrupt processing SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Try: @@ -660,12 +675,12 @@ Try: & SF_String.sfNewLine & .Description _ , MB_OK + MB_ICONSTOP _ , L10N.GetText("ERRORNUMBER", .Number) - .Clear() End With Finally: SF_Utils._ExitFunction(cstThisSub) If _SF_.StopWhenError Then + SF_Exception.Clear() _SF_._StackReset() Stop End If @@ -761,6 +776,8 @@ Const cstThisSub = "Exception.RaiseFatal" Const cstSubArgs = "ErrorCode, [Arg0[, Arg1 ...]]" Const cstStop = "⏻" ' Chr(9211) + ' Save Err, Erl, .. values before any On Error ... statement + SF_Exception._CaptureSystemError() If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch Check: @@ -1016,6 +1033,11 @@ Try: Case FORMCONTROLTYPEERROR ' SF_FormControl._SetProperty(ControlName, FormName, ControlType, Property) sMessage = sLocation _ & " " & " " & .GetText("FORMCONTROLTYPE", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3)) + Case WRITERRANGEERROR ' SF_Writer._ParseRange(TextRange, "TextRange", Scope, Document) + pvArgs(0) = _RightCase(pvArgs(0)) : pvArgs(2) = _RightCase(pvArgs(2)) + sMessage = sLocation _ + & " " & " " & " " & .GetText("VALIDATEERROR", pvArgs(0)) _ + & " " & " " & .GetText("WRITERRANGE", pvArgs(0), pvArgs(1), pvArgs(2), pvArgs(3)) Case DIALOGNOTFOUNDERROR ' SF_Dialog._NewDialog(Service, DialogName, WindowName) pvArgs(0) = _RightCase(pvArgs(0)) : pvArgs(2) = _RightCase(pvArgs(2)) : pvArgs(4) = _RightCase(pvArgs(4)) pvArgs(6) = _RightCase(pvArgs(6)) diff --git a/wizards/source/scriptforge/SF_Services.xba b/wizards/source/scriptforge/SF_Services.xba index f00ad9e94b21..f525d7a447f2 100644 --- a/wizards/source/scriptforge/SF_Services.xba +++ b/wizards/source/scriptforge/SF_Services.xba @@ -105,6 +105,8 @@ Dim vService As Variant ' An individual service object Const cstThisSub = "SF_Services.CreateScriptService" Const cstSubArgs = "Service, arg0[, arg1] ..." + ' Save Err, Erl, .. values before any On Error ... statement + SF_Exception._CaptureSystemError() If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch Set vScriptService = Nothing