IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New From the 10 Commandments of C Programming:
#6: If a function be advertised to return an error code in the event of difficulties, thou shalt check for that code, yea, even though the checks triple the size of thy code and produce aches in thy typing fingers, for if thou thinkest ``it cannot happen to me'', the gods shall surely punish thee for thy arrogance.


And yes, it applies to VB as well. :)
"Here at Ortillery Command we have at our disposal hundred megawatt laser beams, mach 20 titanium rods and guided thermonuclear bombs. Some people say we think that we're God. We're not God. We just borrowed his 'SMITE' button for our fire control system."
New So.
How does one go about making a global error handler?
New In VB?
On Error Resume Next was the most popular method I saw. I wouldn't recomend it myself.

Jay
New Re: In VB?
Yes.
New You can use On Error GoTo
Or at least you could way back in the day.

I don't know whether Microsoft has now added some form of exception handling to the language. If they did, then use that instead. (Unless it is really, really broken.)

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New That's still the way
It's the way Microsoft still does it with the auto code in Office 2003

Private Sub Button_Click
On Error Goto err_Button_Click
   code
   ...
exit_Button_Click:
   Exit Sub
err_Button_Click:
   Msgbox Err.Description
   Resume exit_Button_Click
End Sub


after the err_whatever: tag, you can set up code to compare the Err.Code and handle whatever errors you expect.
~~~)-Steven----

"I want you to remember that no bastard ever won a war by dying for his country.
He won it by making the other poor dumb bastard die for his country..."

General George S. Patton
New That was a joke
That was a joke, not a programming idea. On Error Resume Next tells VB to simply continue with the next step when there is an error. This causes all sorts of havok when there is a real problem.

But if you want a really global error trap, then either put the entire program inside a try/catch block or a global On Error statement at the start.

There isn't much you can do in VB if you catch errors at that level though. All you can do is present some formatted error information and quit.

Jay
New For certain techniques, it works.
Specifically, the practice of manually checking ErrCode after steps that could catastrophically fail. It's a bit lazy, though for some types of code, the risk of an uncaught error is suitably low.

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Opinions vary on "Global" error checking in VB.
But in general, it is thought to be a bad idea. I'm in that camp.

bcnu,
Mikem

Eine Leute. Eine Welt. Ein F\ufffdhrer.
(Just trying to be accepted in the New America)
     Access: Runtime error 91. - (acagle) - (22)
         I think that one means... - (pwhysall) - (10)
             Re: I think that one means... - (acagle) - (9)
                 From the 10 Commandments of C Programming: - (inthane-chan) - (8)
                     So. - (acagle) - (7)
                         In VB? - (JayMehaffey) - (5)
                             Re: In VB? - (acagle) - (4)
                                 You can use On Error GoTo - (ben_tilly) - (1)
                                     That's still the way - (Steven A S)
                                 That was a joke - (JayMehaffey) - (1)
                                     For certain techniques, it works. - (static)
                         Opinions vary on "Global" error checking in VB. - (mmoffitt)
         That's the technical term "set" - (FuManChu) - (4)
             Re: That's the technical term "set" - (acagle) - (3)
                 Yes, unfortunately. - (FuManChu)
                 Putting it in every procedure is good practice for VB. - (mmoffitt) - (1)
                     Dangitall. - (acagle)
         Update: (+edit) - (acagle) - (5)
             You're probably all over this, but... - (Steven A S) - (1)
                 Re: You're probably all over this, but... - (acagle)
             Where is the declaration exactly? And a few more q's. - (mmoffitt)
             Did you get this fixed? -NT - (mmoffitt) - (1)
                 Re: Did you get this fixed? - (acagle)

Ninety-none-point-lots-of-nines percent of the galaxy is empty blackness.
62 ms