Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

[ Create a new account ]

FortKnox (169099)

FortKnox
  (email not shown publicly)
http://www.marotti.com/
AOL IM: joshmarotti (Add Buddy, Send Message)

Read my JE's and you'll figure out everything you need to know about me, eventually. You could also ask.
Does anyone really read these?
Mandatory Amazon Wish List [amazon.com]
My Amigos [slashdot.org]

Journal of FortKnox (169099)

"throws Exception" is not acceptable!!

[ #102460 ]
Wednesday March 30 2005, @04:17PM
User Journal
Ugh, I hate maintaining old code.

Your method should rarely (JUnit tests, and other rare instances) 'throws Exception.'

Its just plain gross. Especially because you were a lazy ass when the only exception BEING thrown is an SQLException!


This code I'm maintaining is from an overseas job.

The only thing I can tell my boss is:
You can't polish a turd


And before ya bitch, I spend all yesterday out with my son riding his bike, then afterward going out to get him ice cream, then up all night with him cause he had leg cramps (must rode too long), so I'll get to the photos late tonight (hopefully... I got training class until at least 9).
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login
Loading... please wait.
  • If the method is supposed to return a value do you want it to return null or some "empty value" if it fails or actually cause an Exception because you're in an exceptional state?
    • "thows Exception" is like saying "thows something" - if your routine throws Foo, Bar, and Baz you should declare it as throwing Foo, Bar, and Baz, so that the caller knows what exceptions to expect (and thus what to catch).

      It's about like writing a routin
    • Throws a generic Exception is not an exceptionl case, because the error, java.lang.Exception, is a generic exception type. If you're in a special case, you'll probably want to trap that with its own type. Throwing Exception just says, "Something happened

    • wowbagger kinda explained it. I'm 100% for Exception throwing, but in java, "java.lang.Exception" is the parent of all exceptions. So if I'm throwing "SQLException" and "NumberFormatError", then both of these method declarations are compilable:
      void foob
  • If it were not for turds found in poor code, how else would root kits steal all of our personal information? I remember back when I thought I was the shizzle for tossing around a little VBScript.... Oh how times have changed... I learned C, C++, PERL, J
  • I thought you were only coding in Satan's language now. What are you doing with an acceptable, nice language? :)
    • I thought I splained it before. I'm in the .NET group, but still do my java work. I'll learn C# and expand my knowledge but most of the jobs I'll be doing is in Java.

      The first thing they want me doing is to make a java API available in C#. So I'm like
  • My current gig is "upgrading" a poorly-written app to use, um, an MVC framework instead of 200 .jsp files.

    Oh, did I mention that one of the first lines of every file is "try" and one of the last lines is "catch (Exception e)"?

    I actually got to talk to th

    • I've done that, but ONLY for R&D work; i.e. never goes to code inspection just has to friggin' run NOW.

      And when I go back to it, (IF anyone ever goes back to it) it gets taken out.

      However I always log log log log logl og lgo gllo gool my exceptions b
      • That shipping program that I wrote actually emails me everytime it throws an exception. Why? because the shipping guys when it gave them an error that said, "X has happened, please notify IT to have this problem diagnosed before closing the window." I'd
        • TL TL TL.....

          You should be catching the exception in your highest level view class (like your actions in struts or servlets if you are doing the old-skool thang), and reporting something nice to the user and logging the actual error and stacktrace.

          Tha
          • That's how I'm doing it now. It's catches each error type that could possibly exist and reports a custom error to the user for each one, along with what they need to do to correct it. But instead of logging it, I'm sending emails to myself and materials (
  • I have just been thrust into a position at my company where some java is a requirement. Since he left so suddenly, and I have proven myself with a number of other projects using php, and I also am the only one that is even slightly familiar with the syste
    • I meant to hit the "plain old text" option.

      Here it is again:

      I have just been thrust into a position at my company where some java is a requirement. Since he left so suddenly, and I have proven myself with a number of other projects using php, and I also
  • You've got no one to blame but yourself. If you had finished unread when you started, the code would no longer be 'old'.

    Is Joey on a two-wheeler? Training wheels? If they're off, I'd love to know how you did it.
  • I'm from the Yoda school of coding:

    Do, or do not. There is no try.
    Before exceptions, there was the setjmp() and longjmp() - messy, so there was an incentive to keep everything clean.

    Now, everyone says "what the hell, I'll just write it and wrap it in

  • I just ran into the analog problem

    try{ .... lots of code ....}
    catch( Exception e )
    { System.out.println("Socket can't connect"); }

    Now while there is lots of socket code, in there, it isn't the only exception throwing code, and because the exception catche
  • Can't you freeze the turd and make an ice sculpture?
  • bananas, calcium (banana milkshake?), and a lot of water

    light stretching

    problems be gone! :-)
    • I just learned about the banana thing. Joey loves bananas, so I'll have to get him eating those daily again... And he's a good milk drinker (at least a (kids) cup a meal), so that isn't an issue.... Thanks for the advice :-D