diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2019-04-26 15:22:22 +0200 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2019-04-26 15:22:22 +0200 |
commit | 75d6bc7abdaad42a20899079cd9e8ff5139fedf1 (patch) | |
tree | 079851ab28e6f130f3a531ac6eda95aca98b9dd1 /wizards/source/access2base | |
parent | b4a1b89cc84086dfd6f471d7f23fecf0ec8f3331 (diff) |
Access2Base - Error handling extended
Error code is captured and made available from outside
the access2base library
Diffstat (limited to 'wizards/source/access2base')
-rw-r--r-- | wizards/source/access2base/Root_.xba | 6 | ||||
-rw-r--r-- | wizards/source/access2base/Trace.xba | 28 | ||||
-rw-r--r-- | wizards/source/access2base/Utils.xba | 17 |
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 ' com.sun.star.beans.Introspection @@ -50,6 +53,9 @@ Private Sub Class_Initialize() TraceLogCount = 0 TraceLogLast = 0 TraceLogMaxEntries = 0 + LastErrorCode = 0 + ErrorText = "" + ErrorLongText = "" CalledSub = "" 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 _ ) -' store error codes in trace buffer +' Store error code and description in trace rolling buffer +' Display error message if errorlevel >= ERROR +' Stop program execution if errorlevel = FATAL or ABORT On Local Error Resume Next If IsEmpty(_A2B_) Then Call Application._RootInit() ' First use of Access2Base in current LibO/AOO session @@ -159,12 +161,16 @@ Dim sErrorText As String, sErrorDesc As String, oDb As Object & " (" & sErrorDesc & ") " & _GetLabel("ERROCCUR") _ & Iif(piErrorLine > 0, " " & _GetLabel("ERRLINE") & " " & CStr(piErrorLine), "") _ & Iif(psErrorProc <> "", " " & _GetLabel("ERRIN") & " " & psErrorProc, Iif(_A2B_.CalledSub = "", "", " " & _Getlabel("ERRIN") & " " & _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) ' Unexpected error detected in user program or in Access2Base If psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT Then - _A2B_.CalledSub = "" 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 ' TraceError V0.9,5 +End Sub ' TraceError V0.9.5 + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function TraceErrorCode(ByVal Optional piMode As Integer) As Variant +' Return the last encountered error code or description +' 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 ' 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) ' Called in bottom of each public function. _A2B_.CalledSub variable is used for error handling ' Used to trace routine in/outs and to clarify error messages If IsEmpty(_A2B_) Then Call Application._RootInit() ' Only is Utils module recompiled - If _A2B_.CalledSub = psSub Then _A2B_.CalledSub = "" - If _A2B_.MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel("Exiting") & " " & psSub & " ...", False) + With _A2B_ + If .CalledSub = psSub Then .CalledSub = "" + If .MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel("Exiting") & " " & psSub & " ...", False) + End With End Sub ' ResetCalledSub REM ----------------------------------------------------------------------------------------------------------------------- @@ -1073,8 +1075,15 @@ Public Sub _SetCalledSub(ByVal psSub As String) ' Called in top of each public function. ' Used to trace routine in/outs and to clarify error messages If IsEmpty(_A2B_) Then Call Application._RootInit() ' First use of Access2Base in current LibO/AOO session - If _A2B_.CalledSub = "" Then _A2B_.CalledSub = psSub - If _A2B_.MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel("Entering") & " " & psSub & " ...", False) + With _A2B_ + If .CalledSub = "" Then + .CalledSub = psSub + .LastErrorCode = 0 + .ErrorText = "" + .ErrorLongText = "" + End If + If .MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel("Entering") & " " & psSub & " ...", False) + End With End Sub ' SetCalledSub REM ----------------------------------------------------------------------------------------------------------------------- |