Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7032673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:57:58+00:00 2026-05-28T00:57:58+00:00

Three ways I see here: 1) make function return that value explicitly 2) add

  • 0

Three ways I see here:

1) make function return that value explicitly

2) add additional argument to the function’s argument list and pass string holder as that parameter. After the function completes its execution, that string holder will contain the result of the function.

3) throw an exception from that function that will contain the result.

I for myself see first choice more preferable because it’s simple, intuitive and straight.

On the other hand, when execution of the function goes in a wrong way there may be additional choices like throw an exception or use a variable passed through parameter to save errors if any happen.

Intuitively, I see that ideal choice is to have explicit return value and throws declaration. So return value is used for normal execution and caught exception will signal about abnormal situation. But I myself don’t like exceptions too much if only it is not the completely unpredictable error, so I’d use explicit return value and additional parameter to hold some extra-situation logs or errors.

Please advise books or articles on the subject (it shouldn’t necessary talk about Java, any other languages with similar mechanisms are also suitable).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:57:59+00:00Added an answer on May 28, 2026 at 12:57 am

    Java methods have return values for a reason: to return their results. In the vast majority of cases #1 should be your only choice. Even if you want to return a wrapper object e.g. because you need to return multiple values, you should probably just return the thing…

    Exceptions are just that: they are thrown in exceptional (i.e. abnormal) circumstances. Since traditionally throwing an exception also implies a performance impact, exceptions should not be thrown during normal operation.

    Why are you trying to confuse yourself?

    EDIT:

    On the other hand, exceptions are quite suitable for rare/abnormal conditions:

    • They have built-in support for the generation of debugging information. Getting a stack trace is half the battle in dealing with most bugs.

    • All decent debuggers allow for thrown exceptions to be used as a break point, which can be invaluable.

    • Exceptions allow for error conditions to be passed up the method call chain relatively transparently, allowing for the error handling code to be placed with as much granularity as desired.

    • Exceptions are the standard way to deal with error conditions in Java. This should be enough for most programmers. Please respect the people that will have to work with your code and don’t break such basic conventions by reinventing the wheel…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make my C# app erase itself (self-destruct)? Here's two ways that
Perl supports three ways (that I know of) of running external programs: system :
I have seen posts that show three ways to reset the DMV views: Reset
I know that technically all three ways below are valid, but is there any
The argument to my function f() must implement two different interfaces that are not
I can see there are many ways to use jQuery safely in the javascript
What are three ways in which web applications can provide a stateful experience for
I know of three ways to get a full language name of a CultureInfo
These are the three ways in which the same image has been referenced to
In VB.Net is there any difference between the following three ways of initialising object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.