|
From: Mike Williams on 22 Jul 2008 09:59 I've never really undersood the error stacks in Windows or the VB Error object and I'd appreciate an answer to a simple "starter" question. Do errors build up in a stack until some action is taken, or are they cleared under certain circumstances (for example exiting a routine). As an admittedly very simple example, suppose I have: Private Function DoSomething() As Boolean Dim n As Long On Error GoTo wayOut ' block of code here perform ' various tasks and set DoSomething ' to True or False as appropriate Exit Function wayOut: DoSomething = False MsgBox "An error occurred in DoSomething" ' I don't do a Resume of any kind 'cos I just want to jump out now End Function Do I need to do anything to the VB Error object before leaving the function (where I am displaying the message box) or will VB take car of this? Also, do blocks of Event code behave in the same way as Subs and Functions regarding error handling? Mike
From: mark.tunnard.jackson on 22 Jul 2008 10:49 > Do I need to do anything to the VB Error object before leaving the function > (where I am displaying the message box) or will VB take car of this? You don't absolutely have to, but I'd recommend using On Error Goto 0 just before End Function. This will clear the Err object. Otherwise the calling routine can read the Err.Number or the Err.Description. Like this: x = DoSomething() If Err.Number <> 0 Then 'This line will be reached if an error occurred in DoSomething End If Not a big deal, but it would be better for DoSomething to tidy up errors that it has dealt with itself, rather than leave them in place.
From: Larry Serflaten on 22 Jul 2008 10:55 "Mike Williams" <mikea(a)whiskyandCoke.com> wrote > I've never really undersood the error stacks in Windows or the VB Error > object and I'd appreciate an answer to a simple "starter" question. Do > errors build up in a stack until some action is taken, or are they cleared > under certain circumstances (for example exiting a routine). They do not build up. You might want to read a few messages from this thread: http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_thread/thread/633ec81412404264/5bae2aa9b86f9746?hl=en&lnk=st&q=#5bae2aa9b86f9746 LFS
From: Jan Hyde (VB MVP) on 22 Jul 2008 11:29 mark.tunnard.jackson(a)googlemail.com's wild thoughts were released on Tue, 22 Jul 2008 07:49:35 -0700 (PDT) bearing the following fruit: >> Do I need to do anything to the VB Error object before leaving the function >> (where I am displaying the message box) or will VB take car of this? > >You don't absolutely have to, but I'd recommend using On Error Goto 0 >just before End Function. This will clear the Err object. Otherwise >the calling routine can read the Err.Number or the Err.Description. >Like this: > >x = DoSomething() >If Err.Number <> 0 Then > 'This line will be reached if an error occurred in DoSomething >End If > >Not a big deal, but it would be better for DoSomething to tidy up >errors that it has dealt with itself, rather than leave them in place. Have you tried that thery out? I think you'll find err.number will be 0 -- Jan Hyde https://mvp.support.microsoft.com/profile/Jan.Hyde
From: Tony Proctor on 22 Jul 2008 11:44 It will be zero if the error was handled by a previous error handler, but it won't be 0 if someone simply used 'On Error Resume Next' inside DoSomething Spotting errors by watching Err.Number is not reliable though as each DLL/EXE has its own Err object. Clearing one doesn't clear others, and setting data in one doesn't set data in others. The only reliable way is to field the associated exception itself (- this would be carried across component boundaries) P.S. Mark: Err.Clear is a better way of clearing the Err object than on 'On Error....' Tony Proctor "Jan Hyde (VB MVP)" <StellaDrinker(a)REMOVE.ME.uboot.com> wrote in message news:s2vb84djtbhu0fv4tfapnl3coromcaqro5(a)4ax.com... > mark.tunnard.jackson(a)googlemail.com's wild thoughts were > released on Tue, 22 Jul 2008 07:49:35 -0700 (PDT) bearing > the following fruit: > >>> Do I need to do anything to the VB Error object before leaving the >>> function >>> (where I am displaying the message box) or will VB take car of this? >> >>You don't absolutely have to, but I'd recommend using On Error Goto 0 >>just before End Function. This will clear the Err object. Otherwise >>the calling routine can read the Err.Number or the Err.Description. >>Like this: >> >>x = DoSomething() >>If Err.Number <> 0 Then >> 'This line will be reached if an error occurred in DoSomething >>End If >> >>Not a big deal, but it would be better for DoSomething to tidy up >>errors that it has dealt with itself, rather than leave them in place. > > Have you tried that thery out? I think you'll find > err.number will be 0 > > > > > > -- > Jan Hyde > > https://mvp.support.microsoft.com/profile/Jan.Hyde
|
Pages: 1 Prev: link site to picture box Next: Sending Mail SMTP High Priority VB6 |