summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2019-04-26 15:22:22 +0200
committerJean-Pierre Ledure <jp@ledure.be>2019-04-26 15:22:22 +0200
commit75d6bc7abdaad42a20899079cd9e8ff5139fedf1 (patch)
tree079851ab28e6f130f3a531ac6eda95aca98b9dd1 /wizards
parentb4a1b89cc84086dfd6f471d7f23fecf0ec8f3331 (diff)
Access2Base - Error handling extended
Error code is captured and made available from outside the access2base library
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/access2base/Root_.xba6
-rw-r--r--wizards/source/access2base/Trace.xba28
-rw-r--r--wizards/source/access2base/Utils.xba17
3 files changed, 44 insertions, 7 deletions
diff --git a/wizards/source/access2base/Root_.xba b/wizards/source/access2base/Root_.xba
index df295f8ca53a..ce82e7d43b7d 100644
--- a/wizards/source/access2base/Root_.xba
+++ b/wizards/source/access2base/Root_.xba
@@ -25,6 +25,9 @@ Private TraceLogs() As Variant
Private TraceLogCount As Integer
Private TraceLogLast As Integer
Private TraceLogMaxEntries As Integer
+Private LastErrorCode As Integer
+Private ErrorText As String
+Private ErrorLongText As String
Private CalledSub As String
Private DebugPrintShort As Boolean
Private Introspection As Object &apos; com.sun.star.beans.Introspection
@@ -50,6 +53,9 @@ Private Sub Class_Initialize()
TraceLogCount = 0
TraceLogLast = 0
TraceLogMaxEntries = 0
+ LastErrorCode = 0
+ ErrorText = &quot;&quot;
+ ErrorLongText = &quot;&quot;
CalledSub = &quot;&quot;
DebugPrintShort = True
Locale = L10N._GetLocale()
diff --git a/wizards/source/access2base/Trace.xba b/wizards/source/access2base/Trace.xba
index a1d214bc4a94..c7bb7a47cbd4 100644
--- a/wizards/source/access2base/Trace.xba
+++ b/wizards/source/access2base/Trace.xba
@@ -148,7 +148,9 @@ Public Sub TraceError(ByVal psErrorLevel As String _
, ByVal Optional pvMsgBox As Variant _
, ByVal Optional pvArgs As Variant _
)
-&apos; store error codes in trace buffer
+&apos; Store error code and description in trace rolling buffer
+&apos; Display error message if errorlevel &gt;= ERROR
+&apos; Stop program execution if errorlevel = FATAL or ABORT
On Local Error Resume Next
If IsEmpty(_A2B_) Then Call Application._RootInit() &apos; First use of Access2Base in current LibO/AOO session
@@ -159,12 +161,16 @@ Dim sErrorText As String, sErrorDesc As String, oDb As Object
&amp; &quot; (&quot; &amp; sErrorDesc &amp; &quot;) &quot; &amp; _GetLabel(&quot;ERROCCUR&quot;) _
&amp; Iif(piErrorLine &gt; 0, &quot; &quot; &amp; _GetLabel(&quot;ERRLINE&quot;) &amp; &quot; &quot; &amp; CStr(piErrorLine), &quot;&quot;) _
&amp; Iif(psErrorProc &lt;&gt; &quot;&quot;, &quot; &quot; &amp; _GetLabel(&quot;ERRIN&quot;) &amp; &quot; &quot; &amp; psErrorProc, Iif(_A2B_.CalledSub = &quot;&quot;, &quot;&quot;, &quot; &quot; &amp; _Getlabel(&quot;ERRIN&quot;) &amp; &quot; &quot; &amp; _A2B_.CalledSub))
+ With _A2B_
+ .LastErrorCode = piErrorCode
+ .ErrorText = sErrorDesc
+ .ErrorLongText = sErrorText
+ End With
If IsMissing(pvMsgBox) Then pvMsgBox = ( psErrorLevel = TRACEERRORS Or psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT )
TraceLog(psErrorLevel, sErrorText, pvMsgBox)
&apos; Unexpected error detected in user program or in Access2Base
If psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT Then
- _A2B_.CalledSub = &quot;&quot;
If psErrorLevel = TRACEFATAL Then
Set oDb = Application.CurrentDb()
If Not IsNull(oDb) Then oDb.CloseAllrecordsets()
@@ -172,7 +178,23 @@ Dim sErrorText As String, sErrorDesc As String, oDb As Object
Stop
End If
-End Sub &apos; TraceError V0.9,5
+End Sub &apos; TraceError V0.9.5
+
+REM -----------------------------------------------------------------------------------------------------------------------
+Public Function TraceErrorCode(ByVal Optional piMode As Integer) As Variant
+&apos; Return the last encountered error code or description
+&apos; UNPUBLISHED
+
+Const cstCode = 0, cstDesc = 1, cstLongDesc = 2
+
+ If IsMissing(piMode) Then piMode = cstCode
+ Select Case piMode
+ Case cstCode : TraceErrorCode = _A2B_.LastErrorCode
+ Case cstDesc : TraceErrorCode = _A2B_.ErrorText
+ Case cstLongDesc : TraceErrorCode = _A2B_.ErrorLongText
+ End Select
+
+End Function &apos; TraceErrorCode V6.3
REM -----------------------------------------------------------------------------------------------------------------------
Public Sub TraceLevel(ByVal Optional psTraceLevel As String)
diff --git a/wizards/source/access2base/Utils.xba b/wizards/source/access2base/Utils.xba
index 56006e555374..07e0d03a3183 100644
--- a/wizards/source/access2base/Utils.xba
+++ b/wizards/source/access2base/Utils.xba
@@ -1041,8 +1041,10 @@ Public Sub _ResetCalledSub(ByVal psSub As String)
&apos; Called in bottom of each public function. _A2B_.CalledSub variable is used for error handling
&apos; Used to trace routine in/outs and to clarify error messages
If IsEmpty(_A2B_) Then Call Application._RootInit() &apos; Only is Utils module recompiled
- If _A2B_.CalledSub = psSub Then _A2B_.CalledSub = &quot;&quot;
- If _A2B_.MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel(&quot;Exiting&quot;) &amp; &quot; &quot; &amp; psSub &amp; &quot; ...&quot;, False)
+ With _A2B_
+ If .CalledSub = psSub Then .CalledSub = &quot;&quot;
+ If .MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel(&quot;Exiting&quot;) &amp; &quot; &quot; &amp; psSub &amp; &quot; ...&quot;, False)
+ End With
End Sub &apos; ResetCalledSub
REM -----------------------------------------------------------------------------------------------------------------------
@@ -1073,8 +1075,15 @@ Public Sub _SetCalledSub(ByVal psSub As String)
&apos; Called in top of each public function.
&apos; Used to trace routine in/outs and to clarify error messages
If IsEmpty(_A2B_) Then Call Application._RootInit() &apos; First use of Access2Base in current LibO/AOO session
- If _A2B_.CalledSub = &quot;&quot; Then _A2B_.CalledSub = psSub
- If _A2B_.MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel(&quot;Entering&quot;) &amp; &quot; &quot; &amp; psSub &amp; &quot; ...&quot;, False)
+ With _A2B_
+ If .CalledSub = &quot;&quot; Then
+ .CalledSub = psSub
+ .LastErrorCode = 0
+ .ErrorText = &quot;&quot;
+ .ErrorLongText = &quot;&quot;
+ End If
+ If .MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel(&quot;Entering&quot;) &amp; &quot; &quot; &amp; psSub &amp; &quot; ...&quot;, False)
+ End With
End Sub &apos; SetCalledSub
REM -----------------------------------------------------------------------------------------------------------------------