Skip to content

Commit 5a5ac6e

Browse files
committed
stdError shouldn't use stdSentry, otherwise cause for an infinite loop in enwrapped branch
1 parent 5fe18a6 commit 5a5ac6e

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/WIP/stdError.cls

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ Attribute VB_PredeclaredId = True
99
Attribute VB_Exposed = False
1010

1111

12-
Private Type TThis
12+
Private Type TThisSingleton
1313
stack as stdArray
1414
RaiseClient As Object 'Allow Raise through a custom userform. Userform should expose a Raise(sMessage, Criticality, Title, StackTrace) method.
1515
End Type
16+
Private Type TThisInstance
17+
xx as string
18+
End Type
19+
20+
Private Type TThis
21+
Singleton As TThisSingleton
22+
Instance As TThisInstance
23+
End Type
1624
Private This as TThis
1725

1826
'New Syntax:
@@ -24,15 +32,21 @@ Private This as TThis
2432
' End With
2533
' end sub
2634
Public Function getSentry(ByVal sSubName As String, ParamArray args() as variant) As Object 'stdSentry
27-
If TypeName(stdSentry) = "stdSentry" Then
28-
Dim vArgs As Variant: vArgs = args
29-
Set getSentry = stdSentry.Create( _
30-
stdCallback.CreateFromObjectMethod(stdError, "addStack").Bind(sSubName, vArgs), _
31-
stdCallback.CreateFromObjectMethod(stdError, "popStack") _
32-
).Run()
33-
End If
35+
Call addStack(sSubName, args)
36+
37+
'A fresh instance acts as a stack popper.
38+
set getSentry = New stdError
3439
End Function
3540

41+
Public Sub Class_Terminate()
42+
'Only do this on fresh instances, not the singleton.
43+
if Me is stdError then Exit Sub
44+
45+
'On class termination, pop the stack.
46+
On Error Resume Next
47+
Call PopStack
48+
End Sub
49+
3650
Public Property Get stack() As stdArray
3751
'Return the stack object, creating it if it doesn't exist.
3852
If this.stack Is Nothing Then

0 commit comments

Comments
 (0)