File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Is this a good coding practice? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "Is this a good coding practice?" Watch "Is this a good coding practice?" New topic
Author

Is this a good coding practice?

Rajesh So
Ranch Hand

Joined: Oct 08, 2002
Posts: 111

This is one of the code piece, where the method has a series of steps to be performed.
The successful execution of the first step is a prerequisite for proceeding with the second step. If there is a failure in step 1, the control should reach the end of the method and continue further.The steps continue this way. The reason for the failure of a step is to be noted in 'valueForReport'. With this in mind, I have used 'success' as a marker for proceeding through all the steps.
Please tell if this way of coding is right/advisable/ideal. If not, how should this situation be handled. I face this kind of situation in my regular work too and hence your suggestion will be very useful.
Thanks in advance,
Rajesh
Marcel de Jong
Ranch Hand

Joined: May 27, 2002
Posts: 54
Hi,
I would write that piece of code like this:

Where the method findFlightUtil(criteria, modelName) throws a DataNotFoundException, or another user defined exception.
In this way you don't need you success variable and in my option its more readable.
Regards,
Marcel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this a good coding practice?
 
Similar Threads
Reading variable size buffer into an byte array
Should we always 'synchronize' the db operations?
Should we always synchronize db operations?
Using Struts and AJAX together causing redirection problems.
Text box JS for '00000' values