- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
*cough* The Java version is not the same as the JDK version, because Sun and Oracle are assholes.
JDK 1.2 through 1.5[1] actually are Java 2, although I'm skipping a bunch of nuance including that part of that version name was retroactive.
[1] Even though JDK 1.5 is for Java 5. Maybe someone wrote something wrong on Wikipedia. I'm not going to get into J2[SME]E, either.
Admin
Well sure, but he said "Java 2.5", that was nice and ambiguous. I guess he could have meant J2SE 5, but that basically equates to Java 1.5 anyway.
Admin
Yeah, I didn't mean to sound like i disagreed with that.
Java/JDK version numbering is approximately as obnoxious as Windows numbering.
Admin
Admin
JdbcTemplate has been part of Spring since
(at least) 2.x1.0.0. Java's version has nothing to do with it.Admin
Yes. That is pretty analogous to the way the JDK and Java versions aren't the same.
Admin
Bradley seems a little too idealistic for somebody who's "seen this antipattern many times before".
This is pretty common shit you have to deal with in the enterprise software world. Go work for a startup if you want to refactor everything on a weekly basis.
Admin
It's been a while since I've done Java, but I remember getting to that point pretty fast. You have some method that can throw 5 types of exceptions and calls 3 methods that each have 5 of their own types of exceptions they can throw, so your declaration is one line of relevant material and 20 lines listing which kinds of exceptions the thing throws.
Change one of the underlying methods to add a 6th exception type, and you have to find all the uses of that thing to update them--which of course we know is a problem in this organization.
/ Couldn't the compiler theoretically keep track of which exceptions get thrown/caught and how they bubble up? Could treat it as a warning or error, or just outright ignore it like these guys would.
Admin
Yet another proof that C#'s way of doing exceptions is better. All hail the high king of languages!
Admin
It can track what is thrown, but not what should be thrown.
Admin
If you believe that, just make all your exceptions inherit from
RuntimeException
. (TheError
subclasses are for shit you can't really do anything about in code, like the JVM throwing a major wobbly.)Admin
The Java way would be better if people only declared checked exceptions when strictly necessary; unfortunately, too many people go overboard with them
Admin
What are you talking about. I have worked on systems that were going very well, and there were over 100,000 items recorded in the tracking system with ZERO performance impact or issues with "hard drive space". With disk space being in the pennies per GB range for even most server environments, this should NEVER be an issue.
Admin
Depends, if the developer do their due diligence and establish proper links to every bog that can be traced back to the "bad code" along with isolating the incremental work that is cause by the "bad code", the evidence can become quite obvious.
Once this happens, raising the issue high enough with the dollars being quantified WILL get the attention of upper management.
Admin
Hi, my name is @izzion and I wrote an extension for a LOB application that threw Exception for pretty much any problem (though not all the way out to the end user).
Oh, right, the Programmer's Anonymous meeting is :arrows: that way
Admin
I don't think any link to Swampy could ever be "proper."
Admin
Admin
Worth an extra like.
Why doesn't the topic exist here already?
Admin
Maybe because Rock Bottom for a programmer is when Paula Bean puts you in a ditch for getting caught fiddling with the code at a shady online casino?
Admin
This has been my experience too. However, many people take the wrong lesson from it. If you look at the decision matrix that those two facts form, you'll see that getting in trouble does not depend on not doing as you're told, it depends on things going wrong. The correct behavior (at least the correct game-theoretic behavior) under these rules is to completely ignore management and do what it takes to make things not go wrong.
Admin
I've learned at school this isn't feasible. So do what it takes to make people believe it's not your fault.
Admin
Every so often I spot someone trying to catch Error in Java. I wonder, what do they think they're going to do with it? (The usual answer is "Log the error and try again" which doesn't help you much when the disk disappears or you encounter a corrupted opcode.)
Admin
Admin
Then each issue gets ignored for years by management because it's not a new feature.
Admin
Well, some errors you can recover from rather easily (missing/badly versioned linkages), and in other cases it might be worth it to at least try and show a nice looking error message instead of Windows Error Reporting.
"Try again" might be an option with OOM, but I wouldn't count on it.
Admin
Emmm... I still think that in Java you throw Exception but catch Throwable instead so you can also catch Error.
So that your function will look unbreakable
Admin
Just what exactly do you plan to do about it? When those sorts of things go wrong, you've typically got no meaningful recovery plan beyond redeploying the application. (Assuming you're not doing dynamic loading of code at that point; you might recover if you are. But probably won't in a way that anyone really wants.)
That (plus logging the problem, but that's just “nice” for the developers/deployers) is the only good reason for doing it I can think of.
Admin
I think you'll find that the interface in question was http://docs.spring.io/spring/docs/2.5.x/api/org/springframework/jdbc/core/JdbcOperations.html
Oh, look at that – version 2.5. You know, the article didn't say Java version 2.5.
Admin
What that takes is avoiding doing anything that might leave your fingerprints on anything that might go wrong.
Admin
Is that anything like http://docs.spring.io/spring-framework/docs/1.0.0/api/org/springframework/jdbc/core/JdbcOperations.html ?
Admin
I've worked in alternate dimensions where "refactor" meant "add new features". I got there after Management learned that refactoring was important but didn't want developers wasting time on something else when they could instead be adding the latest shiny thing. Clearly the solution was to redefine the word.
Admin
They're easy enough to find, but you've got to make sure you get exclusive use of the stall first.
Admin
I didn't say it wasn't in spring before version 2.5.
Admin
Filed under: http://thedailywtf.com/articles/Exceptionally-Hard-to-Swallow
Admin
This runs afoul of rule #2:
I don't see why you would believe you would get in trouble for legitimately not making a change, yet get away with it if it only appeared you didn't make a change.Admin
You can have it throw a supertype of each exception. Or just let the IDE do all the work (IntelliJ does, I'm fairly sure Eclipse/Netbeans do too) With multi-catch blocks you don't have that many problems...
Admin
Both are a bit.
I have a similar conundrum with a legacy code base where it is hard to add significant unit tests. Though tools like VCS, testing environments, etc keep things sane enough. I still spend a lot of time refactoring. Otherwise the technical debt would be fatal. In that situation you don't let people refactor unless you trust them though.
Admin
Which makes this statement
the true :wtf: yeah yeah yeah. Find a new job first before burning bridges...
Admin
Bill looked upon Java, and saw a confusion of new language concepts. "This new-fangled stuff is a evil," he opined.
Recoiling in horror, he took a deep breath and declared, "Let there be C."
And there was C. And Bill saw the C and saw that it was good." And may C reign in Bill's code base forever and ever.
Admin
So... is TRWTF the lack of logging, unit testing, and integration testing as a change management backstop being used as an excuse for Bill's self-serving obstructionist policies, or is it Bradley's intransigence in the face of those policies? You make the call!
Though it isn't as if we haven't covered this ground before. I say we should award Bill and Bradley a joint WTF for their (un)cooperative effort. What says the Academy?
Admin
You can still catch any sub-type of Exception. If a method throws generic Exception but you want to specifically deal with IOException you can catch IOException only and only that will be dealt with. You only need a second catch block that catches exception (or method must also throw exception again).
The better idea however is to get rid of this checked exception BS and only extend from RuntimeException which is unchecked.
Admin
But then you get the problem of people not actually trying to handle exceptional cases at all (so a butterfly's sneeze kills the program), or handling everything with the moral equivalent of
ON ERROR GOTO NEXT
.Admin
O.o
No, you should throw Exception subclasses when appropriate and throw RuntimeExceptions when they're appropriate
Admin
which IIRC is, according to the official Java documentation that i can't he tailed to look up at the moment, only appropriate if one of following conditions occur:
Admin
https://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html seems to imply that it's ok if it's unrecoverable in general.
But using only RuntimeExceptions is crazy and a terrible idea. Plus it's against the "standard"...
Relevant quote:
Admin
Strictly, errors are for unrecoverables, runtimeexceptions are for unlikely-to-want-to-recover-froms, and other exceptions are for you-ought-to-think-about-handling-this.
Admin
which means that it's only okay in java core (or possibly when interfacing with custom hardware)
anything that involves remote server communications or internal calculations, or basically anything that is not local hardware can be recovered from.... in theory.
Admin
Yeah.
Using a good IDE and modern Java version (1.7+) a lot of the exception problems are pretty irrelevant. At least if you've done the sub-exceptions right. Multi-catch and catching supertypes cut down on your issues.
Example: Not good:
Good:
Or, even shorter...
Admin
Well... Yeah, actually, that's probably accurate. It's hard to think of an example of a RuntimeException that's not just bubbling one up from core. The case may exist though...
Admin
*hasn't written Java code since
1.5*