File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

design choice: to return from a catch block

 
Mohit Sinha
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I would like to know your thoughts if using a statement like "return output;" in the catch block is a good design practice.
The design contract we have with the external calling entity is to populate the output object with values and success message in case of success and error code and error message in case of failure.
We do not propagate a java exception back to the external calling entity but instead capture the details of the exception in the catch block, populate the output object with the relevant exception details and send it back to the external calling entity.
Now my question is this design approach right to return back from a catch block. This way I am actually trying to exit from the particular flow of the program.
There are also scenarios (some catch blocks) where we will not return i.e exit the program flow. Instead just log the exception and proceed with the next step in the flow.

Do let me know your thoughts.

Regards,
Mohit
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's a totally valid coding practice, although I would advise to use it carefully.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic