Author | Topic |
Location: Sydney
Registered: July 2002
|
Re: hey java buffs
|
Tue, 06 May 2003 07:46
|
|
Nark wrote on Tue, 06 May 2003 15:51 | Depends on how everything is set up. Stuff like null pointers shouldn't create a stack trace if it's fixable.
I wouldn't put a try loop JUST to catch a NullPointerException, I'd just put the if blocks around it.
But sometimes you can fix it elegantly with a catch for null pointers. Like verify that the rest of the data is clean or even throw more exceptions for them to casade outward.
Really depends on your architecture.
|
Sorry I was a bit vage. I meant your IF statement was the right way to go (you are right, I'm not dissagreeing with you), but a specific try BLOCK (its a block not a bloody "loop"!! ) for just a null pointer is silly. Which is exactly what you said in the quote.
As for elegant catches YUK. No such thing. A catch is ONLY if there is something that wasn't expected. If there is a possibility there is a null, test for it, don't expect the try block to pick it up. Putting more than e.printStackTrace() or throwing another exception within a catch block is disgusting code.
I didn't know there were this many java learners/programmers in Toymods . Just remember grasshopper(s):
Computers are a great way to make money. Money that can be spent on doing up toyotas!
|
|
|