Function NewExceptionHandler(ByRef lpExceptionPointers As EXCEPTION_POINTERS) As Long ' No need to return a value since Err.Raise will alter execution flow Dim er As EXCEPTION_RECORD Dim sError As String ' Make a copy of the exception record portion ' of the passed-in EXCEPTION_POINTERS structure CopyMemory er, ByVal lpExceptionPointers.pExceptionRecord, Len(er) ' Set up error description string Do sError = GetException(er.ExceptionCode) ' Special treatment for access violation -- get addresses If sError = EXCEPTION_ACCESS_VIOLATION Then sError = sError & - Instr @ &H & Hex(er.ExceptionAddress) _ & tried illegally to _ & IIf(er.ExceptionInformation(0) = 0, _ read from address , write to address ) _ & &H & Hex(er.ExceptionInformation(1)) End If ' Check for nested error If er.pExceptionRecord = 0 Then Exit Do |