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

  • Home
  • SEARCH
  • 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 8602885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:11:47+00:00 2026-06-12T02:11:47+00:00

I am having a function that does a DB operation and sends a boolean

  • 0

I am having a function that does a DB operation and sends a boolean value for success/failure. suppose it fails, i want to send the failure reason as a return value.

for now, i have defined return value as a string. if it is failure i return "failure: reason" and if it is success, i return "success". but this is not good practice.

  • 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-06-12T02:11:48+00:00Added an answer on June 12, 2026 at 2:11 am

    This is what you use throw exception for. You can very well change your method signature and set the return value to be boolean. Then create a custom Exception class:

    public class MyCustomException extends RuntimeException {
        // define error code, error message etc.
        // create getters & setters
    }
    

    After that, whenever you find a reason for failure, do this:

    if (some_failure_reason == true) {
        throw new MyCustomException(error_code) ;
    }
    

    In your controller (or service), catch the exception:

    try {
        // call the method in question
    } catch (MyCustomException mce) {
        if(mce.getErrorCode() == some_error_code) {
            // do stuff
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that generates normal random number matrix having normal distribution using
I'm having a bit of trouble with a a function that the mongodb c
I'm having a problem trying to create a Javascript function that checks all the
I'm trying to define a delegate function that will return an IEnumerable. I'm having
I am having difficulties with my state machine. I use a function that returns
I'm having a problem with using this in js. I have a function that
I often hear around here from test driven development people that having a function
I'm having trouble with something that I understand should function out of the box
How does boost::function take a function pointer and get parameters from it? I want
Im having this function to determine weather a user exists in a database or

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.