Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Programming] Am I the only one...?
#10
You need to remember that all exceptions thrown that aren't OutOfMemoryError, StackOverflowError, NullPointerException and the like are not thrown by the JVM, but by the classes that come with Java.

Plus Exceptions provide an easy way to give error descriptions. For example if there were a problem reading from disk due to corrupted sector.

Would you rather say "Error reading from disk." or "Error reading from disk: corrupted sector"?

I'd choose the latter.

Throwing an exception is better and provides more information for the programmer and end-user. Just returning null.. eh, no thank you.

At least in Java and most languages you are restricted to throwing only some type.

In C++ you can throw ints, strings, objects, null, etc

No joke.

In the end it's all up to your style. For me, I would check for simple things such as invalid user input and stuff before executing. If an exception occurs, then something really bad happened. Smile

Try-catch does not end up in buggy or unpredictable code. And some exceptions can't be avoided. Try-catch is not poor programming.
Reply


Messages In This Thread
[Programming] Am I the only one...? - by Fiel - 2009-09-30, 06:45 PM
[Programming] Am I the only one...? - by Nikkey - 2009-09-30, 07:03 PM
[Programming] Am I the only one...? - by Fiel - 2009-09-30, 07:09 PM
[Programming] Am I the only one...? - by Cyadd - 2009-09-30, 07:30 PM
[Programming] Am I the only one...? - by Spaz - 2009-09-30, 07:45 PM
[Programming] Am I the only one...? - by Nikkey - 2009-09-30, 07:49 PM
[Programming] Am I the only one...? - by Fiel - 2009-09-30, 08:13 PM
[Programming] Am I the only one...? - by AngelSL - 2009-10-04, 01:30 AM

Forum Jump:


Users browsing this thread: