Kaydet (Commit) 75d6bc7a authored tarafından Jean-Pierre Ledure's avatar Jean-Pierre Ledure

Access2Base - Error handling extended

Error code is captured and made available from outside
the access2base library
üst b4a1b89c
...@@ -25,6 +25,9 @@ Private TraceLogs() As Variant ...@@ -25,6 +25,9 @@ Private TraceLogs() As Variant
Private TraceLogCount As Integer Private TraceLogCount As Integer
Private TraceLogLast As Integer Private TraceLogLast As Integer
Private TraceLogMaxEntries As Integer Private TraceLogMaxEntries As Integer
Private LastErrorCode As Integer
Private ErrorText As String
Private ErrorLongText As String
Private CalledSub As String Private CalledSub As String
Private DebugPrintShort As Boolean Private DebugPrintShort As Boolean
Private Introspection As Object ' com.sun.star.beans.Introspection Private Introspection As Object ' com.sun.star.beans.Introspection
...@@ -50,6 +53,9 @@ Private Sub Class_Initialize() ...@@ -50,6 +53,9 @@ Private Sub Class_Initialize()
TraceLogCount = 0 TraceLogCount = 0
TraceLogLast = 0 TraceLogLast = 0
TraceLogMaxEntries = 0 TraceLogMaxEntries = 0
LastErrorCode = 0
ErrorText = ""
ErrorLongText = ""
CalledSub = "" CalledSub = ""
DebugPrintShort = True DebugPrintShort = True
Locale = L10N._GetLocale() Locale = L10N._GetLocale()
......
...@@ -148,7 +148,9 @@ Public Sub TraceError(ByVal psErrorLevel As String _ ...@@ -148,7 +148,9 @@ Public Sub TraceError(ByVal psErrorLevel As String _
, ByVal Optional pvMsgBox As Variant _ , ByVal Optional pvMsgBox As Variant _
, ByVal Optional pvArgs 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 On Local Error Resume Next
If IsEmpty(_A2B_) Then Call Application._RootInit() ' First use of Access2Base in current LibO/AOO session 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 ...@@ -159,12 +161,16 @@ Dim sErrorText As String, sErrorDesc As String, oDb As Object
& " (" & sErrorDesc & ") " & _GetLabel("ERROCCUR") _ & " (" & sErrorDesc & ") " & _GetLabel("ERROCCUR") _
& Iif(piErrorLine > 0, " " & _GetLabel("ERRLINE") & " " & CStr(piErrorLine), "") _ & Iif(piErrorLine > 0, " " & _GetLabel("ERRLINE") & " " & CStr(piErrorLine), "") _
& Iif(psErrorProc <> "", " " & _GetLabel("ERRIN") & " " & psErrorProc, Iif(_A2B_.CalledSub = "", "", " " & _Getlabel("ERRIN") & " " & _A2B_.CalledSub)) & 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 ) If IsMissing(pvMsgBox) Then pvMsgBox = ( psErrorLevel = TRACEERRORS Or psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT )
TraceLog(psErrorLevel, sErrorText, pvMsgBox) TraceLog(psErrorLevel, sErrorText, pvMsgBox)
' Unexpected error detected in user program or in Access2Base ' Unexpected error detected in user program or in Access2Base
If psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT Then If psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT Then
_A2B_.CalledSub = ""
If psErrorLevel = TRACEFATAL Then If psErrorLevel = TRACEFATAL Then
Set oDb = Application.CurrentDb() Set oDb = Application.CurrentDb()
If Not IsNull(oDb) Then oDb.CloseAllrecordsets() If Not IsNull(oDb) Then oDb.CloseAllrecordsets()
...@@ -172,7 +178,23 @@ Dim sErrorText As String, sErrorDesc As String, oDb As Object ...@@ -172,7 +178,23 @@ Dim sErrorText As String, sErrorDesc As String, oDb As Object
Stop Stop
End If 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 ----------------------------------------------------------------------------------------------------------------------- REM -----------------------------------------------------------------------------------------------------------------------
Public Sub TraceLevel(ByVal Optional psTraceLevel As String) Public Sub TraceLevel(ByVal Optional psTraceLevel As String)
......
...@@ -1041,8 +1041,10 @@ Public Sub _ResetCalledSub(ByVal psSub As String) ...@@ -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 ' 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 ' Used to trace routine in/outs and to clarify error messages
If IsEmpty(_A2B_) Then Call Application._RootInit() ' Only is Utils module recompiled If IsEmpty(_A2B_) Then Call Application._RootInit() ' Only is Utils module recompiled
If _A2B_.CalledSub = psSub Then _A2B_.CalledSub = "" With _A2B_
If _A2B_.MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel("Exiting") & " " & psSub & " ...", False) If .CalledSub = psSub Then .CalledSub = ""
If .MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel("Exiting") & " " & psSub & " ...", False)
End With
End Sub ' ResetCalledSub End Sub ' ResetCalledSub
REM ----------------------------------------------------------------------------------------------------------------------- REM -----------------------------------------------------------------------------------------------------------------------
...@@ -1073,8 +1075,15 @@ Public Sub _SetCalledSub(ByVal psSub As String) ...@@ -1073,8 +1075,15 @@ Public Sub _SetCalledSub(ByVal psSub As String)
' Called in top of each public function. ' Called in top of each public function.
' Used to trace routine in/outs and to clarify error messages ' 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 IsEmpty(_A2B_) Then Call Application._RootInit() ' First use of Access2Base in current LibO/AOO session
If _A2B_.CalledSub = "" Then _A2B_.CalledSub = psSub With _A2B_
If _A2B_.MinimalTraceLevel = 1 Then TraceLog(TRACEDEBUG, _GetLabel("Entering") & " " & psSub & " ...", False) 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 End Sub ' SetCalledSub
REM ----------------------------------------------------------------------------------------------------------------------- REM -----------------------------------------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment