PDA

View Full Version : Solved: Unusual Error Trap



Dr.K
03-10-2009, 07:18 AM
I am building a new report, I am trying to salvage some code from a previous one. This guy's code is kinda weird, and he is long gone so I can't ask him.

Anyone ever seen an error trap like this?

'On Error GoTo ErrorHandling
If 1 = 2 Then On Error GoTo ErrorHandling


What the hell? when would 1 ever = 2?

Is this a joke?

nst1107
03-10-2009, 07:25 AM
That's pretty funny. Can you find a variable in his code that he may have meant to type instead of 1?

Cosmo
03-10-2009, 07:47 AM
Although the commented out line above suggests otherwise, perhaps this was his way of turning on or off the errorHandling, possibly during debugging. I'd guess that since he didn't know that he could just use 'If false...' ( or even comment or uncomment the line, or just manually bypass the error handling line) then maybe he didn't know a better way to bypass the error handling.

Dr.K
03-11-2009, 11:25 AM
Yeah, thats clearly it: a way to enable/disable error trapping globally, by using a global Find and Replace. Since you would NEVER use 1=1 or 1=2 in your real code, the F&R won't effect any of your code.

Makes some sense.

Bob Phillips
03-11-2009, 12:34 PM
Although the commented out line above suggests otherwise, perhaps this was his way of turning on or off the errorHandling, possibly during debugging. I'd guess that since he didn't know that he could just use 'If false...' ( or even comment or uncomment the line, or just manually bypass the error handling line) then maybe he didn't know a better way to bypass the error handling.

Why would you want to bypass it? Wy have it at all if you want to bypass it?

Dr.K
03-11-2009, 01:23 PM
I often disable the Error Traps for testing purposes.

I build my Error Traps with the end user in mind, not me. When testing I want to get the standard error break dialog when something goes wrong. This is especially important with ADO SQL errors, which are descriptive and helpful to ME, but not the end users.

Cosmo
03-11-2009, 01:38 PM
Why would you want to bypass it? Wy have it at all if you want to bypass it?I have no idea, I just figured that was my best guess at what the original coder had done. When I'm rewriting code in my programs, I often put the old/new code in an 'If True Then..Else..End ' block so I can test the new code without completely disabling the old code. I figured since he was effectively saying 'If False, then on error...' that was his intention.

Bob Phillips
03-11-2009, 02:31 PM
I add a comment tick, pretty efficient.