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         =       
&quot;BASEFORMNOTFOUNDERROR&quot;
 Const SUBFORMNOTFOUNDERROR             =       &quot;SUBFORMNOTFOUNDERROR&quot;
 Const FORMCONTROLTYPEERROR             =       &quot;FORMCONTROLTYPEERROR&quot;
 
+&apos; SF_Writer
+Const WRITERRANGEERROR                 =       &quot;WRITERRANGEERROR&quot;
+
 &apos; SF_Dialog
 Const DIALOGNOTFOUNDERROR              =       &quot;DIALOGNOTFOUNDERROR&quot;
 Const DIALOGDEADERROR                  =       &quot;DIALOGDEADERROR&quot;
@@ -282,6 +285,8 @@ Dim oNonModalBtn As Object                  &apos;  Non 
modal close button
 Const cstThisSub = &quot;Exception.Console&quot;
 Const cstSubArgs = &quot;[Modal=True]&quot;
 
+       &apos;  Save Err, Erl, .. values before any On Error ... statement
+       SF_Exception._CaptureSystemError()
        If SF_Utils._ErrorHandling() Then On Local Error GoTo Finally   &apos;  
Never interrupt processing
 
 Check:
@@ -339,6 +344,8 @@ Dim lConsole As Long                &apos;  UBound of 
ConsoleLines
 Const cstThisSub = &quot;Exception.ConsoleClear&quot;
 Const cstSubArgs = &quot;[Keep=0]&quot;
 
+       &apos;  Save Err, Erl, .. values before any On Error ... statement
+       SF_Exception._CaptureSystemError()
        If SF_Utils._ErrorHandling() Then On Local Error GoTo Finally   &apos;  
Never interrupt processing
 
 Check:
@@ -382,6 +389,8 @@ Dim sLine As String                                 &apos;  
A single line
 Const cstThisSub = &quot;Exception.ConsoleToFile&quot;
 Const cstSubArgs = &quot;FileName&quot;
 
+       &apos;  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 = &quot;Exception.DebugDisplay&quot;
 Const cstSubArgs = &quot;Arg0, [Arg1, ...]&quot;
 
+       &apos;  Save Err, Erl, .. values before any On Error ... statement
+       SF_Exception._CaptureSystemError()
        If SF_Utils._ErrorHandling() Then On Local Error Goto Finally   &apos;  
Never interrupt processing
        SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
 Try:
@@ -475,6 +486,8 @@ Const cstMaxLength = 1024
 Const cstThisSub = &quot;Exception.DebugPrint&quot;
 Const cstSubArgs = &quot;Arg0, [Arg1, ...]&quot;
 
+       &apos;  Save Err, Erl, .. values before any On Error ... statement
+       SF_Exception._CaptureSystemError()
        If SF_Utils._ErrorHandling() Then On Local Error Goto Finally   &apos;  
Never interrupt processing
        SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
 Try:
@@ -577,6 +590,8 @@ Const cstPyHelper = &quot;$&quot; &amp; 
&quot;_SF_Exception__PythonPrint&quot;
 Const cstThisSub = &quot;Exception.PythonPrint&quot;
 Const cstSubArgs = &quot;Arg0, [Arg1, ...]&quot;
 
+       &apos;  Save Err, Erl, .. values before any On Error ... statement
+       SF_Exception._CaptureSystemError()
        If SF_Utils._ErrorHandling() Then On Local Error Goto Finally   &apos;  
Never interrupt processing
        SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
 Try:
@@ -660,12 +675,12 @@ Try:
                                                                                
                &amp; SF_String.sfNewLine &amp; .Description _
                                                                                
        , MB_OK + MB_ICONSTOP _
                                                                                
        , L10N.GetText(&quot;ERRORNUMBER&quot;, .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 = &quot;Exception.RaiseFatal&quot;
 Const cstSubArgs = &quot;ErrorCode, [Arg0[, Arg1 ...]]&quot;
 Const cstStop = &quot;⏻&quot;          &apos; Chr(9211)
 
+       &apos;  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       &apos;  
SF_FormControl._SetProperty(ControlName, FormName, ControlType, Property)
                                sMessage = sLocation _
                                        &amp; &quot;
&quot; &amp; &quot;
&quot; &amp; .GetText(&quot;FORMCONTROLTYPE&quot;, pvArgs(0), pvArgs(1), 
pvArgs(2), pvArgs(3))
+                       Case WRITERRANGEERROR           &apos;  
SF_Writer._ParseRange(TextRange, &quot;TextRange&quot;, Scope, Document)
+                               pvArgs(0) = _RightCase(pvArgs(0))       :       
pvArgs(2) = _RightCase(pvArgs(2))
+                               sMessage = sLocation _
+                                       &amp; &quot;
&quot; &amp; &quot;
&quot; &amp; &quot;
&quot; &amp; .GetText(&quot;VALIDATEERROR&quot;, pvArgs(0)) _
+                                       &amp; &quot;
&quot; &amp; &quot;
&quot; &amp; .GetText(&quot;WRITERRANGE&quot;, pvArgs(0), pvArgs(1), pvArgs(2), 
pvArgs(3))
                        Case DIALOGNOTFOUNDERROR        &apos;  
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                             &apos;  
An individual service object
 Const cstThisSub = &quot;SF_Services.CreateScriptService&quot;
 Const cstSubArgs = &quot;Service, arg0[, arg1] ...&quot;
 
+       &apos;  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
 

Reply via email to