|
My head hurts from banging it on my desk. Just came across this beauty in the 'else' statement of some code I'm debugging (not mine, of course):
MessageBox.Show("Should never get this message.");
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
That's awesome. It's what happens when you feel you need a try but have no clue what to do in the event it ever does fail.
Also, it could be that if the developers ever saw it then they knew some approach was not working and could fix it but assumed their approach was right and therefore should never see it.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have gotten some of those before. Had a look at the code and can't see how it could possibly get there. Normally it is an indication that something has gone awry. Possibly stack corruption or something like that. The thing is they don't normally print the if or case bits so you haven't a clue how it got there.
|
|
|
|
|
I can beat that - some code I was asked to help with had hundreds of methods where a database query was wrapped with:
try
{
}
catch (Exception exception)
{
exception.Message.ToString();
throw new Exception("Exception occured");
}
Needless to say, every call to one of these methods was wrapped with:
try
{
CallTheQueryMethod();
}
catch (Exception exception)
{
MessageBox.Show(this, exception.Message);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yeah, that's nice too. I've also come across several completely empty catch statements. Those are fun to debug: "Error? What error?"
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
This is probably because the programmer didn't know how to handle the error or what to do with it.
|
|
|
|
|
All programming is about handling errors. A whole life is about handling errors, actually. I bet the programmer was a no-lifer.
Greetings - Jacek
|
|
|
|
|
|
Here on Code Project somebody made an excellent point about empty catches: This piece of code
try {
SaveUserData();
}
catch
{
}
is equivalent to:
try {
}
catch
{
}
Greetings - Jacek
|
|
|
|
|
Wow, this post's timing is perfect. I've been tracking down a bug this morning where data is not being saved to a database table when it should be (in the same code that started this thread). It came down to an error being thrown by the database, but caught in an empty catch statement. As frustrating as that is, it has been going on for a couple of years...nobody seemed to care until now, so why bother?
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
But at least it compiles, doesn't it???
I think some people use exceptions only when they have to. For example in java your code wouldn't compile without catching it or declaring the exception in the signature of the function that encloses your code. Result: people catch it and either ignore it or "return false;" or "return null;". Problem solved.
|
|
|
|
|
Hmmmm
I was once interviewed by a person who had asked me "Why are Exceptions Bad?"....
Without catching the drift of his tone, I replied "I don't think Exception are bad" ....
Interview ended few seconds after that
I guess I was lucky that I did not get the Job!!!
|
|
|
|
|
Well, it depends on the language and the scenario. I personally love exception handling but in some cases I avoid using exceptions. For example in C++ I don't like it because the rules are too loose (you can throw by value, reference, pointer, there is no standard exception base class/exception chaining): the result is that most libraries simply don't use it or use it only internally. If you have to wire together several libraries with their own exception types that can also be a pain in the ass. Another scenario where the presence of exception handling sometimes matters is extremely performance critical, maybe low level code.
One of my friend told me a tale about one of his job interviews. The interviewer ask him the following question: "What is the purpose of smart pointers?". Of course my friend told a tale about object ownership and resource allocation/deallocation. Finally the interviewer gave him the right answer: "Smart pointers are useful because of the exceptions!". It clearly shows the incompetence of the iterviewer, he simply didn't understand that smart pointers are just a possible application of RAII, and he has no clue about object ownership, RAII,...
|
|
|
|
|
This just shows the incompetence of the programmer who wrote it: he didn't understand a core feature of the used language: exception handling/propagation. The result is extremely hard time or mission impossible when it comes to finding bugs especially from user error reports (without stacktrace of course). If you get a job and you see code like this I recommend doing the following:
- ask someone whether a total refactorization is possible (maybe not because of time, safe-player boss, ...)
- if refactor is not possible then search for your next job
Working on such a codebase is a waste of time from your valuable life.
|
|
|
|
|
have to admit that I am guilty of doing this one sometimes. in my defense, I only do this in debug code and I try to not let it go into production.
kind of like having a default on switch block used with an enumeration. if you have handled all of the values in your case statements the default should never hit. if default is hit that means someone changes the enumeration or something else really bad happened.
you want something inspirational??
|
|
|
|
|
Unfortunately, this is in production code. I've replaced it to throw an error instead, which is what should have been done in the first place.
The word "never" is a red flag for me. My experience has been that when ever someone uses the word "never", code for it anyway. It will probably come back to haunt you someday if you don't. In this case, I don't think any users have actually seen this message, but you 'never' know...
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
NickPace wrote: My experience has been that when ever someone uses the word "never", code for it anyway. It will probably come back to haunt you someday if you don't. I can attest to that.
I like to do similar stuff in situations where some kind of assertion looks like the right thing to do, but I cannot think of anything that could happen breaking the assertion. It's my way of saying "I don't expect anything bad to happen here, but I do expect the unexpected!"
(then again, I usually just use assert s, not message boxes... )
|
|
|
|
|
What do you think of this? Yesterday I had an exception thrown by the exception handler which caused another... Exception. The log file simply exploded! Had to stop the service..
What was the problem: a new user tried to login without credentials yet saved in the Human Resources DB but already on Active Directory. Why can the HR department be empty when somebody new starts?
The signature is in building process.. Please wait...
|
|
|
|
|
vonb wrote: Why can the HR department be empty when somebody new starts? Simple: the home office downsizes your local HR presence to a single overworked and harassed individual. Despite her angelic personality and the patience of Buddha, sh!t still happens.
Software Zen: delete this;
|
|
|
|
|
Gary Wheeler wrote: home office downsizes your local HR presence
The problem is: it is already the home office where I work... And there is a MAIN rule: 50 % office occupation is MANDATORY. Who invented that: HR...
The signature is in building process.. Please wait...
|
|
|
|
|
Actually themessage ought to read: "Something really bad happened".
And that's unfinished code. Someone placed this as a marker in the code to be reminded that something more has to be written.
|
|
|
|
|
I still like the ones that you used to see a lot of the form:
description of the problem<br />
Cancel this action?<br />
<br />
[OK] [Cancel]
which leaves the user in a complete quandry. Does [OK] mean 'yes,I want to cancel' and [Cancel] mean 'No, please cancel the Cancel'; or does [OK] mean 'continue without cancelling' and [Cancel] mean 'Yes, cancel is what I want to do'? Plus, there is no indication of what dire effects either of thse two options have.
|
|
|
|
|
Just for fun, have a look at this:
http://imagesup.net/?di=213751878365[^]
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.
|
|
|
|
|
This reminds me of a message that some code of my former employer produced.
It was saying "These shoes are to large for you!" every time some absurd socket implementation tried to put large data into a length limited stream and the data was to big.
When the original developer returned to the company one day and the developer currently responsible for the code told him what strange error messages one customer was receiving that poor guy said "What?! That message wasn't supposed to be seen by anyone..."
|
|
|
|
|
I see it's time for the resident dinosaur to ring in...
Way back when -- Was it the Obscene Era, or the Cretinaceous? I forget -- I was attempting a feat that, happily, is no longer important to anyone not yet mummified: channel programming on an IBM 360/67. Channel programming was necessary to do "access method" development for IBM-style disk packs. If you've never seen that phrase before, combine the worst aspects of assembler with completely, deliberately opaque documentation in faded typescript, and remove any trace of debugging facilities. It's possible that no one outside IBM itself has ever understood channel programming; despite my youthful bravado, I never did.
Anyway, I'd misunderstood something in that faded typescript and had gone "one level too indirect" in a data structure critical to my channel program. Accordingly, it crashed the system completely, occasioning a cold-start reboot and bringing the wrath of the system administrators (and quite a few other programmers) down on my poor head. It was a traumatic event, to be sure. But what I'll remember all the way into the afterlife was the error message on my printout:
Channel command error encountered:
Please correct your program before re-running it.
I'm told that there are programmers who disdain exceptions and exception handling as "too difficult." Fancy that.
(This message is programming you in ways you cannot detect. Be afraid.)
|
|
|
|