VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ErrObject"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private e() As ErrObjectState

Private Type ErrObjectState
    Description As String
    HelpContext As Long
    HelpFile As String
    Number As Long
End Type


Property Get HelpFile() As String
    HelpFile = VBA.err.HelpFile
End Property

Property Let HelpFile(ByVal newValue As String)
    VBA.err.HelpFile = newValue
End Property

Property Get Source() As String
    Source = VBA.err.Source
End Property

Property Let Source(ByVal newValue As String)
    VBA.err.Source = newValue
End Property

Property Get Number() As Long
Attribute Number.VB_UserMemId = 0
    Number = VBA.err.Number
End Property

Property Let Number(ByVal newValue As Long)
    VBA.err.Number = newValue
End Property

Property Get HelpContext() As Long
    HelpContext = VBA.err.HelpContext
End Property

Property Let HelpContext(ByVal newValue As Long)
    VBA.err.HelpContext = newValue
End Property

Property Get Description() As String
    Description = VBA.err.Description
End Property

Property Let Description(ByVal newValue As String)
    VBA.err.Description = newValue
End Property

Public Sub Raise(Number As Long, Optional Source As String, _
        Optional Description As String, Optional HelpFile As String, Optional HelpContext As Long)
        
    VBA.err.Raise Number, Source, Description, HelpFile, HelpContext
        
End Sub

Public Sub Clear()

    VBA.err.Clear
    Description = vbNullString
    HelpContext = VBA.err.HelpContext
    HelpFile = VBA.err.HelpFile
    Number = VBA.err.Number
End Sub

Public Sub Push()
    ReDim Preserve e(UBound(e) + 1) As ErrObjectState
    With e(UBound(e))
        .Description = Description
        .HelpContext = HelpContext
        .HelpFile = HelpFile
        .Number = Number
    End With
End Sub

Public Sub Pop()
    With e(UBound(e))
        Description = .Description
        HelpContext = .HelpContext
        HelpFile = .HelpFile
        Number = .Number
    End With

    If UBound(e) Then
        ReDim e(UBound(e) - 1) As ErrObjectState
    Else
        VBA.err.Raise Number:=28    ' Out of stack space - underflow
    End If
End Sub

Private Sub Class_Initialize()
    ReDim e(0) As ErrObjectState
End Sub

Private Sub Class_Terminate()
    Erase e()
End Sub
