aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes exception vs error code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "exception vs error code" Watch "exception vs error code" New topic
Author

exception vs error code

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

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 ?


SCJP, SCJD, SCWCD, OCPJBCD
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
I think an int type. The meaning of its value is agreed upon in the program.


--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Jon Entwistle
Ranch Hand

Joined: Feb 20, 2003
Posts: 118
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


SCJD, SCEA
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception vs error code