Re: Err object being reset and returning err.number = 0
From: Jezebel (madbastard_at_whitehouse.gov)
Date: 01/20/05
- Next message: TC: "Re: Err object being reset and returning err.number = 0"
- Previous message: Joseph Geretz: "Re: COM Interface Security"
- In reply to: TC: "Err object being reset and returning err.number = 0"
- Next in thread: TC: "Re: Err object being reset and returning err.number = 0"
- Reply: TC: "Re: Err object being reset and returning err.number = 0"
- Reply: gmaxey_at_mvps.org: "Re: Err object being reset and returning err.number = 0"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 20 Jan 2005 14:39:11 +1100
An error-handling routine should end with some form of resume statement,
otherwise your subsequent code is still within the error-handling context,
which screws up the handling of any further error. A better construction is
along these lines (remove the bits you don't need) --
Sub Something()
Const pFunctionName = "Something"
Dim pErrorResponse as long
On Error Goto Something_Error
' routine goes here
Something_Exit:
On error resume next
... function clean-up if any
Err.clear
Exit Sub
Something_Error:
Select case err.number
Case vbObjectError
' special handling, if any
Case Else
pErrorResponse = Msgbox(err.description, vbIgnoreRetryCancel,
pFunctionName)
End Select
If pErrorResponse = vbRetry then Resume
If pErrorResponse = vbIgnore then Resume Next
Resume Something_Exit
End Sub
"TC" <getmyemails2@yahoo.com> wrote in message
news:ujpHb$p$EHA.1604@TK2MSFTNGP12.phx.gbl...
Hello,
I am experiencing an odd and intermittent problem with a COM addin that I've
built. I have seen this problem once before in a Word global template.
Imagine code structured like the following pseudo-code:
Sub Something
On Error Goto ErrorHandler
' routine goes here
ErrorHandler:
If err.number <> 0 then
ErrorMessage err
end if
End Sub
Sub ErrorMessage(byval objErr as ErrObject)
msgbox "Error: " & objErr.Number & vbcr & "Description: " &
objErr.Description
End Sub
If the above routine causes an error, the message box returned reveals
"Error: 0", i.e. no error, but this is not possible because otherwise, the
ErrorMessage routine would not be called.
I resolved this once before by passing in the err.number & err.description
values as opposed to the err object itself. It was as if the OS was losing
its thread to the err object.
Has anyone else experienced this?
Regards,
TC
- Next message: TC: "Re: Err object being reset and returning err.number = 0"
- Previous message: Joseph Geretz: "Re: COM Interface Security"
- In reply to: TC: "Err object being reset and returning err.number = 0"
- Next in thread: TC: "Re: Err object being reset and returning err.number = 0"
- Reply: TC: "Re: Err object being reset and returning err.number = 0"
- Reply: gmaxey_at_mvps.org: "Re: Err object being reset and returning err.number = 0"
- Messages sorted by: [ date ] [ thread ]