- 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
I suspect this person was using an IDE which suggested wrapping the line which throws an exception in a try catch block to get around the compilation error. If it's the one I'm thinking about, it would have added the code for him/her as well if s/he wanted.
This is what happens when you let a machine do the thinking for you.
Admin
Admin
If you have any complex conversation on Java through sockets, the only reliable way of interrupting a thread that is expecting a message is closing the socket.
This throws exceptions, and even if the docummented way of thread.interrupt worked, it would also throw an exception. Often, there is nothing you want to do with this exception... And, yes, this API is crap.
Admin
A better way to write this would be
Admin
Aaahh... Memories bring me back....
Reminds me of my first job as a programmer (in 1996) where a coleague writing Visual Basic had some stupid error popping up once in a while in a large project.... One day he was absolutely gleaming with joy as he solved the problem:
On error resume next
It was a glorious day for him!!!
Admin
No, Out of memory and other hard exceptions are subclasses of Error in Java, not Exception. So they wouldn't be caught. Things may be different in C#, at least I've found one logfile chock-full of reports about OutOfMemoryExceptions.
Admin
Ummmm...guys, I think the idea is to see a message on the "exceptions" console, then continue....
Admin
The method doesn't have to throw an Exception, cause its already caught within the method and never leaves it.
Admin
Well I believe that is not true. The caught Exception is still of the type that is actually thrown. So you will at least be able to read out its message. And with .getClass(). you can even retrieve its actual type. Though that is not the way to do it. And catching a highest level Exception is still a WTF in most cases.
Admin
Would this work? :p
Admin
I meant this:
Admin
dispite that it will end in an infinite loop, I can see no syntax errors. :)
Admin
catch { throw new Exception ("blah"); }
then the PHB got a complaint about error "blah" popping up all the time and sends coder B in to squelch it. Instead of simply commenting out the throw statement, they decided to wrap it in a try..catch block and swallow the new exception.
Admin
Ah, I see. In that case, yes that would be pretty crap API :) .
Admin
I can (almost) see a possible use for this (albeit an ugly one) -- if the Exception being created was instead a custom one which wrote to a log file. I've seen it before, and it's a cheap way of logging any custom exception.
Admin
i guess the developer did not want to outsource the exception handling.
Admin
Something I recently found among my old source (comment left intact for your amusement):
try { url = new URL("http://www.obfuscated.com/server.php"); } catch (MalformedURLException e) { // THIS CAN NEVER EVER HAPPEN! System.out.println("DANGER! REALITY DAMAGED!"); System.exit(1); }
One of the few cases where it makes sense for the API to throw an exception, and makes no practical sense for me to catch it (since the URL is hardcoded and will not ever change).
Captcha: ewww, very fitting.
Admin
Looks like debug code to me...
Presume the IDE/debugger normally breaks execution at the point an exception is raised.
Some types of exception are configured to be ignored from the IDE (so they do not break execution). This is usually done for exceptions that occur regularly within code as part of normal runtime behaviour.
The code happens to throw one of the 'ignored' exceptions, but the programmer wanted to have the debugger break even thought that 'ignored' exception occurred. (e.g. the 'ignored' exception occurs a million times elsewhere (poor programming style?) during execution so they want to ignore it!)
The programmer wants to squelch the exception in a production environment.
I admit it - I recognise the idiom because I have used it in another language (although at least I commented the reason).
Admin
Actually, when I read this, it made me throw up in my mouth a little.
-Todd Put down the sig. and step away from the computer.
Admin
If this is debug code, it needs to be commented (as you said you did). But I'm surprised no one commented on the other comment here, the totally useless javadoc comment auto-generated by the IDE.
The app I'm working on is full of these, and none of the other programmers seem to care or think it's worthwhile to write javadoc. Or, if they do, they add their comment below the junk spewed out by the IDE, so you will see something like:
Or:
It drives me nuts!
Admin
Oh my lord! I practically had a heart attack seeing that. Now that would make a great WTF.