Re: How to HANDLE an Access Violation error

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Ivan Debono (ivanmdeb_at_hotmail.com)
Date: 01/20/05


Date: Thu, 20 Jan 2005 13:48:04 +0100

The MSDN states that the error mode is for a process and its child
processes. Does this mean that unhandled exceptions within called DLL's and
OCX's are handled by the parent process (EXE) too?

Ivan

"alpine" <alpine_don'tsendspam@mvps.org> schrieb im Newsbeitrag
news:ftsiu09f5t1dmr8gamn98u9ui6gbdcerjf@4ax.com...
> Here is a simple example....
>
> ' form code
> Option Explicit
>
> Private Sub Form_Load()
>
> SetErrorMode SEM_NOGPFAULTERRORBOX
>
> SetUnhandledExceptionFilter AddressOf UnhandledExceptionFilter
>
> End Sub
>
> Private Sub Command1_Click()
>
> On Error GoTo EH
>
> ' oops :-)
> CopyMemory ByVal 0, ByVal 10, 1000
>
> ExitNow:
> Exit Sub
>
> EH:
> MsgBox "The following error occured: " & CStr(Err.Number) &
> vbNewLine & Err.Description, vbExclamation
> Resume ExitNow
>
> End Sub
> ' end form code
>
> ' UEF function from BAS module
> Public Function UnhandledExceptionFilter(ExceptionInfo As
> EXCEPTION_POINTERS) As Long
>
> Dim nLastDllErr&, nBuffLen&, lpBuffer&, sErrorMessage$
>
> nLastDllErr = Err.LastDllError
>
>
> If nLastDllErr Then
> nBuffLen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER Or
> FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, nLastDllErr, 0&, lpBuffer, 0&,
> ByVal 0&)
>
> If nBuffLen Then
> sErrorMessage = String$(nBuffLen, vbNullChar)
>
> CopyMemory sErrorMessage, lpBuffer, nBuffLen
>
> Call LocalFree(lpBuffer)
>
> sErrorMessage = StrConv(sErrorMessage, vbUnicode)
> End If
>
> Else
> nLastDllErr = vbObjectError + 1
> End If
>
> If Len(sErrorMessage) = 0 Then
> sErrorMessage = "Error unknown. What ever it was that you did,
> DON'T DO IT AGAIN!"
> End If
>
>
> UnhandledExceptionFilter = EXCEPTION_EXECUTE_HANDLER
>
>
> Err.Raise nLastDllErr, "You goofus!", sErrorMessage
>
> End Function
> ' end UEF function
>
>
> HTH,
> Bryan
> ____________________________________________________________
> New Vision Software "When the going gets weird,"
> Bryan Stafford "the weird turn pro."
> alpine_don'tsendspam@mvps.org Hunter S. Thompson -
> Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
>
>
> On Sat, 15 Jan 2005 14:04:55 -0500, "Al Meadows"
> <fineware@fineware.com> wrote:
>
> >That is something I've had problems figuring out. If I raise an error in
> >the UnhandledExceptionFilter, it simply raises it again in the
> >UnhandledExceptionFilter.
> >
> >Must be I'm doing something wrong.
> >
> >Can you show me a short UnhandledExceptionFilter function, forget all of
the
> >bells and whistles than you can extract from it, but show me how to make
it
> >trigger back to the original function?
> >
> >Example:
> >
> >Sub someFunction
> >on error goto errorHit:
> >...
> >doSomething
> >...
> > exit sub
> >errorHit:
> > msgbox "found error"
> >end sub
> >
> >Function UEF_Function(etc)
> > ....
> > 'comment = what do I put here
> >
> >end Function
> >
> >
> >Al
> >
> >"alpine" <alpine_don'tsendspam@mvps.org> wrote in message
> >news:m0dgu0htfk67cluq8firqisrbd9h0q4f2o@4ax.com...
> >> On Fri, 14 Jan 2005 11:43:02 -0800, "Al Meadows"
> >> <AlMeadows@discussions.microsoft.com> wrote:
> >>
> >>>How do I Handle and trap an Access Violoation error instead of having
it
> >>>call
> >>>my UnhandledExceptionFilter routine where it doesn't necessarily know
> >>>where
> >>>the problem arose?
> >>>
> >>>Basically, I just want it to fall into the specific routine's own On
Error
> >>>GoTo errorHit routine.
> >>>
> >>>Al Meadows
> >>
> >> Once you've handled the exception in your UnhandledExceptionFilter are
> >> you then raising it back to your VB error handler via the Err.Raise
> >> method?
> >>
> >> HTH,
> >> Bryan
> >> ____________________________________________________________
> >> New Vision Software "When the going gets weird,"
> >> Bryan Stafford "the weird turn pro."
> >> alpine_don'tsendspam@mvps.org Hunter S. Thompson -
> >> Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
> >
>



Relevant Pages

  • Re: How to HANDLE an Access Violation error
    ... Private Sub Form_Load ... SetUnhandledExceptionFilter AddressOf UnhandledExceptionFilter ... On Error GoTo EH ... Dim nLastDllErr&, nBuffLen&, lpBuffer&, sErrorMessage$ ...
    (microsoft.public.vb.winapi)
  • Re: How to HANDLE an Access Violation error
    ... That is something I've had problems figuring out. ... the UnhandledExceptionFilter, it simply raises it again in the ... Sub someFunction ... >>GoTo errorHit routine. ...
    (microsoft.public.vb.winapi)