Comment On The Perils of Error-free Code

Writing error-free code in Visual Basic is a cinch; just tack "On Error Resume Next" up at the top, and you're good to go. But when it comes to Java and C#, it's a bit more of a pain. As Dave found out, you have to wrap every single line with some silly Try/Catch block ... [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: The Perils of Error-free Code

2006-02-06 14:46 • by First
heh.

Re: The Perils of Error-free Code

2006-02-06 14:46 • by steve
my eyes are bleeding

Re: The Perils of Error-free Code

2006-02-06 14:48 • by DotNot

That is just fscking ridiculous.  I can't believe someone would go to those lengths to avoid ever getting an error... ever (much less never know if their code is ever working or not).

Re: The Perils of Error-free Code

2006-02-06 14:52 • by java.lang.NullReferenceException
It is just beatiful. Is this method patented, or can I use it in my own code without licensing fees? ;-)



It is just amazing that this guy managed to keep his thinking inside
the box. I imagine that each step down this evolutionary dead-end must
have been initiated by the thought "there must be a better way to do
this", never followed by the thought "I must be on the wrong track"...

Re: The Perils of Error-free Code

2006-02-06 14:53 • by Anonymous jr.
I SO do not believe this is for real.
This is made up.

Re: The Perils of Error-free Code

2006-02-06 14:53 • by Pyromancer
59184 in reply to 59181

fifth?


When sinner programmers die, they are dragged to hell and forced to debug erorrless programs like that [6]

Re: The Perils of Error-free Code

2006-02-06 14:54 • by toxik
Must've been an "Aha!" feeling when he noticed that try {} can do more
then one line, and that the if statement has been around for some
time...

Re: The Perils of Error-free Code

2006-02-06 15:11 • by mjonhanson
I'm suprised he didn't rewrite the class loader.  That would be a fun one to debug in hell.  6

Re: The Perils of Error-free Code

2006-02-06 15:16 • by paddy
My groin!

The cup, it does nothing!



Getting quick and easy to follow feedback from where one of your
programs screws up has long been a problem in programming.  If you
can do away with catching errors well enough, you should be able to
ensure the database just gets silently corrupted data or something,
that way its the DB admin's problem, and there are no blemishes come
review time for that vacant management position.

Re: The Perils of Error-free Code

2006-02-06 15:20 • by Devils Advocate
Okay, I'm going to poke a few here, but the first sentence got me.

"On Error Resume Next"

As a (typically) non-VB programmer, this strikes me as:

"I'm not going to write well written code, if something goes wonky, just ignore it and keep on truckin'!"

Now, this to me, seems like it might work in the non-production scripting world, but is this seriously the "recommended practice" for dealing with realtime errors?

Thanx
Diablo.

Re: The Perils of Error-free Code

2006-02-06 15:24 • by Rain dog
59189 in reply to 59188
Ok, where is this guy so we can all go beat him up.

btw, CAPTHA is not color blind friendly.

Re: The Perils of Error-free Code

2006-02-06 15:32 • by scriptkiddie
59190 in reply to 59188
1st post here after months of lurking...

Anonymous:
Okay, I'm going to poke a few here, but the first sentence got me.

"On Error Resume Next"

As a (typically) non-VB programmer, this strikes me as:

"I'm not going to write well written code, if something goes wonky, just ignore it and keep on truckin'!"

Now, this to me, seems like it might work in the non-production scripting world, but is this seriously the "recommended practice" for dealing with realtime errors?

Thanx
Diablo.


On Error Resume Next does have its place if you are testing to see if, for instance, a certain activex object can be instantiated or not, without having your script bug out... but it is seriously misused by the masses in exactly the way you describe... and of course, use of activex might be viewed as a wtf in itself!

Re: The Perils of Error-free Code

2006-02-06 15:32 • by Gene Wirchenko
Alex Papadimoulis:
Writing error-free code in Visual Basic is a cinch; just tack "On Error Resume Next" up at the top, and you're good to go.

Thankfully, Petr Lazecky was able to step before this eclipsed to the next level of WTF and impacted a serious project. But it certainly is an interesting example of just how far one can go down the wrong path with creative invention ...

I am reminded of a quote from Hoare.  Paraphrase: There are two ways to program: so that there are obviously no errors and so that there are no obvious errors.

This WTF is definitely in the second category.  If I ran into this in production code, I would be rather angry.  The potential for a big mess as a result of this WTF is too likely.

Sincerely,

Gene Wirchenko

Re: The Perils of Error-free Code

2006-02-06 15:33 • by marvin_rabbit
This just makes the Baby Jesus cry.

Re: The Perils of Error-free Code

2006-02-06 15:34 • by Asztal
59193 in reply to 59185
Ah, but if you use try{} over more than one line, then if the first statement fails, the rest are not executed.

Re: The Perils of Error-free Code

2006-02-06 15:35 • by Oli

I can imagine his rationale - "well it didn't fall over, so there ARE no bugs!"

Re: The Perils of Error-free Code

2006-02-06 15:36 • by marvin_rabbit
59195 in reply to 59188
Anonymous:

"On Error Resume Next"
<clip>
Now, this to me, seems like it might work in the non-production scripting world, but is this seriously the "recommended practice" for dealing with realtime errors?

Alex was being ironic (not moronic).

Re: The Perils of Error-free Code

2006-02-06 15:41 • by Runtime Error
59197 in reply to 59183
Anonymous:
I SO do not believe this is for real.
This is made up.




Ahh... the joyous innocence of youth.  You should really try to
stay away from here Anonymous Jr.  This place isn't good for
you.  Its like the cliffs note version of things that man was not
meant to know and can't be unlearned.



Most of the people that have been around for a while not only believe
that its for real, we have had to fix these things.  Although I'm
not really sure what would be the proper tool for fixing this one, fire
I would guess.

Re: The Perils of Error-free Code

2006-02-06 15:45 • by Runtime Error
59199 in reply to 59186
mjonhanson:
I'm suprised he didn't rewrite the class loader.  That would be a fun one to debug in hell.  6




Thats funny, I was thinking some type of AOP wrapper would be the
easiest way to implement the "Hear No Evil, See No Evil, Speak No Evil"
design pattern.  But I bow to your superiour wisdom, a hacked
class loaded is definetly the way to go. 

Re: The Perils of Error-free Code

2006-02-06 15:47 • by OneMHz
59200 in reply to 59188
Anonymous:
Okay, I'm going to poke a few here, but the first sentence got me.

"On Error Resume Next"

As a (typically) non-VB programmer, this strikes me as:

"I'm not going to write well written code, if something goes wonky, just ignore it and keep on truckin'!"

Now, this to me, seems like it might work in the non-production scripting world, but is this seriously the "recommended practice" for dealing with realtime errors?

Thanx
Diablo.


Sense of sarcasm anyone?  :-P

Re: The Perils of Error-free Code

2006-02-06 15:59 • by ChiefCrazyTalk
59201 in reply to 59188

Anonymous:
Okay, I'm going to poke a few here, but the first sentence got me.

"On Error Resume Next"

As a (typically) non-VB programmer, this strikes me as:

"I'm not going to write well written code, if something goes wonky, just ignore it and keep on truckin'!"

Now, this to me, seems like it might work in the non-production scripting world, but is this seriously the "recommended practice" for dealing with realtime errors?

Thanx
Diablo.


 


It depends on what the "next" is in resume next.  This should be some sort of error handler, if coded correctly.

Re: The Perils of Error-free Code

2006-02-06 15:59 • by Randolpho

What. The. Fuck.


Seriously, I've seen some semi-sorta excusable WTFs here; fringe areas where the WTF might be OK... but this one... very highly WTF. So WTF that I can't possibly think *why* any programmer would ever want to do such a thing.


Hmm........


 


however.......


 


Now that I think about it, isn't this pretty much what C programmers who ignore return codes do? [:$]

Re: The Perils of Error-free Code

2006-02-06 16:01 • by merreborn
59203 in reply to 59193
Anonymous:
Ah, but if you use try{} over more than one line, then if the first statement fails, the rest are not executed.



You say that like it's a bad thing.

Wait, is my sarcasm meter dead again?

Re: The Perils of Error-free Code

2006-02-06 16:04 • by Romeo
My eyes! The Google! They do nothing!

Re: The Perils of Error-free Code

2006-02-06 16:05 • by Manni
59205 in reply to 59188

Devils Advocate:
Okay, I'm going to poke a few here, but the first sentence got me.

"On Error Resume Next"

As a (typically) non-VB programmer, this strikes me as:

"I'm not going to write well written code, if something goes wonky, just ignore it and keep on truckin'!"

Now, this to me, seems like it might work in the non-production scripting world, but is this seriously the "recommended practice" for dealing with realtime errors?

Thanx
Diablo.


"On Error Resume Next" does have its place in the VB world, but just like anything else, in the wrong hands it can wreak havoc.


Your interpretation of the statement is fairly accurate. However you can test at any point in your code to see if an error occurred, and account for it (this is how you tell good programmers from hobbyists). These errors don't necessarily result from poorly written code, there are plenty of valid reasons: database server went down as the program was running, query timeout was exceeded, no read permission on remote files, etc etc. This is stuff you can't always test for or anticipate.


One alternative is "On Error Goto", which is just frickin scary and amateurish to use. I want to handle my errors, not jump to a certain line in my code whenever something goes wrong. I suppose you could just omit error-handling completely and let the program crash when you encounter such a problem. I wouldn't recommend it.

Re: The Perils of Error-free Code

2006-02-06 16:06 • by Rank Amateur

I have to commend Dave on his ingenuity, but he's clearly ignorant of the true essence of programming. The true way is to never bother with try{}blocks at all. If your code compiles, then, by definition, it's error free. If it crashes, it's someone else's fault. I usually blame Microsoft and say nothing can be done about it.


--Rank


Do. Or do not. There is no try{}.  --Yoda


 

Re: The Perils of Error-free Code

2006-02-06 16:12 • by jmeyer43
59207 in reply to 59201

No, in VB next means next... in this case, handle errors by going to the next statement and continuing!


Of course I whole-heartedly agree abuot what the error handler SHOULD do, but VB's "on error resume next" doesn't do any of that

Re: The Perils of Error-free Code

2006-02-06 16:24 • by Sean
This one is more nightmarish than funny.  Someone like this discovering generics is like a baby finding a loaded handgun.

Re: The Perils of Error-free Code

2006-02-06 16:31 • by cm5400
Wow Oh Wow.  My EYES are on fire![:S]

Re: The Perils of Error-free Code

2006-02-06 16:34 • by foxyshadis
59212 in reply to 59186
mjonhanson:
I'm suprised he didn't rewrite the class loader.  That would be a fun one to debug in hell.  6

Wouldn't it be easier to just wrap every single called method, then import the wrappers instead of the real libraries? More complex probably, but cut-n-paste easier. Just catch everything and return false. Plus it works seamlessly with normal code libraries, so you can replace coworkers' code with throw-free versions! You just have to install the wrapper library.

Well, I guess that goes for the classloader too.

Re: The Perils of Error-free Code

2006-02-06 16:35 • by Wayne

I love it.  A WTF with generic delegates.  This is a bleeding-edge WTF.

Re: The Perils of Error-free Code

2006-02-06 16:37 • by Gene Wirchenko
59214 in reply to 59207
jmeyer43:
No, in VB next means next... in this case, handle errors by going to the next statement and continuing!

Of course I whole-heartedly agree abuot what the error handler SHOULD do, but VB's "on error resume next" doesn't do any of that


You can interrogate the error status at any point, but it is too easy to miss a point.  If you do not anticipate a particular statement throwing an error, then you will never see one.

Sincerely,

Gene Wirchenko

Re: The Perils of Error-free Code

2006-02-06 16:41 • by Manni
59215 in reply to 59207
jmeyer43:

No, in VB next means next... in this case, handle errors by going to the next statement and continuing!


Of course I whole-heartedly agree abuot what the error handler SHOULD do, but VB's "on error resume next" doesn't do any of that



What would you rather have it do? Is there another language that automatically does something (other than crash the program) whenever an error is generated? If so, please tell me so I can begin using it immediately.


On Error Resume Next is basically like putting every statement in a try block with an empty catch after it. It's up to the programmer to fill in the catch block. Don't blame the language when people produce stupid code. As you can see with today's WTF, it's just as probable in a non-VB environment.

Re: The Perils of Error-free Code

2006-02-06 16:57 • by Phil

I've never seen such a nitpicky, jealous group before.


Your code is only this error-free in your dreams.

Re: The Perils of Error-free Code

2006-02-06 17:00 • by rbriem
59217 in reply to 59206

Rank Amateur:


Do. Or do not. There is no try{}.  --Yoda



Now *that's* funny!

Re: The Perils of Error-free Code

2006-02-06 17:01 • by maht
59218 in reply to 59205
Manni:

On Error Goto", which is just frickin scary and amateurish to use.



not necessarily, it is just the same as resume next but the lines are shuffled about so that it just pops the error handling code away from the eyes, exceptions should be exceptional



Exit Sub

errorsgotohere:

' clean up or back out
resume

End Sub


btw. the CAPTCHA is typing blind


Re: The Perils of Error-free Code

2006-02-06 17:13 • by triso
59219 in reply to 59197
Anonymous:
[...Although I'm
not really sure what would be the proper tool for fixing this one, fire
I would guess.


Firing would be a better solution.

Re: The Perils of Error-free Code

2006-02-06 17:31 • by triso
59221 in reply to 59209
Sean:
This one is more nightmarish than funny. 
Someone like this discovering generics is like a baby finding a loaded
handgun.
Hence the expression, "A little knowledge is a dangerous thing." --Alexander Pope

Re: The Perils of Error-free Code

2006-02-06 17:32 • by bit
59222 in reply to 59207
Well. It's been some time since I last saw a true WTF like this one. I mean, you have to try hard not to shout "WhatTheF...!" or burst in a histerical laughter at the sight of this. Truly enjoyable. For those of us who don't have to cope it, that is.

Re: The Perils of Error-free Code

2006-02-06 17:47 • by FrostCat
59223 in reply to 59201
Anonymous:

Anonymous:
Okay, I'm going to poke a few here, but the first sentence got me.

"On Error Resume Next"

As a (typically) non-VB programmer, this strikes me as:

"I'm not going to write well written code, if something goes wonky, just ignore it and keep on truckin'!"

Now, this to me, seems like it might work in the non-production scripting world, but is this seriously the "recommended practice" for dealing with realtime errors?

Thanx
Diablo.


 


It depends on what the "next" is in resume next.  This should be some sort of error handler, if coded correctly.



 


And this case, "correctly" probably means using "on error goto", not "on error resume next".


 


This post not [pi]-approved.

Re: The Perils of Error-free Code

2006-02-06 17:48 • by bit
59224 in reply to 59207
jmeyer43:

No, in VB next means next... in this case, handle errors by going to the next statement and continuing!


Of course I whole-heartedly agree abuot what the error handler SHOULD do, but VB's "on error resume next" doesn't do any of that



No, but you have to do it. ON ERROR RESUME NEXT is the way to tell the compiler explicitly that you are handling your errors in place, and don't want to mess with explicit handlers or worse, get the program to crash without explanation. Use it, and it will make your life easy. Abuse it, and hell ensues.

Re: The Perils of Error-free Code

2006-02-06 17:54 • by dasmb
The real amazing thing here is that the .NET "solution" is technically pretty complex and requires advanced knowledge of delegation.

Meaning that what we have is not the "Brillant" programmer who has no talent, but a rather smart guy who just doesn't get it.

But then, in our industry more horrors have been created out of cleverness than out of stupidity.  Just ask any Notes developer (provided he isn't doped up on morphine...i understand that's the only way some of them make it through the day).

Re: The Perils of Error-free Code

2006-02-06 17:57 • by bit
59228 in reply to 59224
bit:
jmeyer43:

No, in VB next means next... in this case, handle errors by going to the next statement and continuing!


Of course I whole-heartedly agree abuot what the error handler SHOULD do, but VB's "on error resume next" doesn't do any of that



No, but you have to do it. ON ERROR RESUME NEXT is the way to tell the compiler explicitly that you are handling your errors in place, and don't want to mess with explicit handlers or worse, get the program to crash without explanation. Use it, and it will make your life easy. Abuse it, and hell ensues.


Just to clarify: it's wonderful to have proper error handling methods. By using ON ERROR RESUME NEXT you're explicitly opting for an "old school" style of programming, in which you refuse to use those methods and manually anticipate your error scenarios. As Gene pointed out, this is not the best thing to do. But, anyway, even when using the fanciest error handling system, you have to cope with the errors in the code of your handler, so you are already anticipating error conditions, right?

Re: The Perils of Error-free Code

2006-02-06 18:01 • by chrismcb
59230 in reply to 59205
Manni:

One alternative is "On Error Goto", which is just frickin scary and amateurish to use. I want to handle my errors, not jump to a certain line in my code whenever something goes wrong. I suppose you could just omit error-handling completely and let the program crash when you encounter such a problem. I wouldn't recommend it.



Actually it is called an exception handler and it is how professionals handle exceptions in their code. This allows you to have a generic exception handler to handle the exceptions.  


IF you don't do this, your program will crash. Letting your program crash is pretty scary and amatuerish. I would want to handle my errors, and not just crash whenever something goes wrong.


I guess I don't understand how you plan on handling your errors WITHOUT using on error goto?

Re: The Perils of Error-free Code

2006-02-06 18:10 • by McTesty
59231 in reply to 59230
Aw man, it would have been so easy to add error logging to his delegate and made this entire WTF go away!

Re: The Perils of Error-free Code

2006-02-06 18:28 • by FunnyMan
59232 in reply to 59224
bit:
ON ERROR RESUME NEXT is the way to tell the compiler explicitly that you are handling your errors in place, and don't want to mess with explicit handlers or worse, get the program to crash without explanation. Use it, and it will make your life easy. Abuse it, and hell ensues.


A few years back I had the misfortune of trying to develop a basic MUD client in VB.  This heinous construction was actually amazingly useful, because I was writing an end-user program.  My errors were always things that if it didn't work, the user would notice and try again, so it was far preferable to ignore the errors than to have the program crash every time they did something that wasn't quite right or the server wouldn't take the connection.

Thankfully, I've long since learned how to use proper error handling.  Even when you don't care about an error, you should at least have the decency to catch only that particular error, so that other problems surface when you need them to.

-FM

Re: The Perils of Error-free Code

2006-02-06 18:33 • by FunnyMan
59233 in reply to 59230
chrismcb:
Actually it is called an exception handler and it is how professionals handle exceptions in their code. This allows you to have a generic exception handler to handle the exceptions. 

IF you don't do this, your program will crash. Letting your program crash is pretty scary and amatuerish. I would want to handle my errors, and not just crash whenever something goes wrong.


I guess I don't understand how you plan on handling your errors WITHOUT using on error goto?

The better solution is to have the error handling alongside the code that triggers that error (with, say, a try-catch block).  It makes it easier to figure out which error is being handled by what code, and if you happen to have a bunch that all need the same fix, you dump it in a function and call the function.  I'm thankfully not up to date on VB, so I can't tell you if such a construction even exists, but it's definitely the Right Way to handle errors (unless used as above).

-FM

Re: The Perils of Error-free Code

2006-02-06 18:38 • by RB
59234 in reply to 59206

Do. Or do not. There is no try{}.  --Yoda


 


yeah but there's a catch{} to everything


 

Re: The Perils of Error-free Code

2006-02-06 18:42 • by Runtime Error
59236 in reply to 59233
Whie the Java version is nice, there is still to much code hardcoded in
the, uh, code.  What he needs to do is to move all those function
names and arguments to an XML file and write a class to parse that and
execute it through reflection, all the while discarding all those pesky
exceptions.

Re: The Perils of Error-free Code

2006-02-06 18:45 • by tim
59237 in reply to 59180
Anonymous:
my eyes are bleeding

I'm right there with you.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment