• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

exception vs error code  RSS feed

 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I prepare my self for the dev. exam and I have a small dilemma the "error code".
In Katty & Bert on chapter 12 I found :

"Do Not Return Error Codes! This is Java. This is OO. If you really need to indicate an exceptional condition, use an Exception! If you really want to annoy an assessor, use error codes as return values from some of your methods. Even one method might do the trick."

Somethig similar I found in M.Habibi "The sun certified java developer exam ..." in chapter 2 : "Checked exception should be uses to report expected events ...."


What is a error code ?
In the java api (collerction by example) all the data manipulation method rerun a boolean (Inidcates the success/failure of the operation), in the
M.Habibi book the same stuff(public synchronized boolean addDVD(DVD dvd) throws IOException{ ... ) is this boolean a error code or not ?
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think an int type. The meaning of its value is agreed upon in the program.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The error codes refered to are ways used in languages such as C to determine an exit condition of a procedure when something unexpected has happened - a non zero value where each value indicates what happened (e.g. errno value 5 means an IO error has occurred). You should not do this in your code - we are lucky enough to have exceptions and we would rightly be marked down for not using them when appropriate.

cheers

Jon
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree about the "C" error code style.That is logic.
In the other words when a method tries to accomplish a task, olny two possible scenario.It accomplish the task or not, and this can be checked with the boolean retun value.If an expected (or unexpected) event happens during the method task an exception(checked or unchecked) is raised.
Now I have a clear overview.
ThanX.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!