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 7075643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:12:07+00:00 2026-05-28T06:12:07+00:00

I trying to improve my skills using Try Catch blocks and better error handling.

  • 0

I trying to improve my skills using Try Catch blocks and better error handling.

I have a class that performs a common task, in this case retrieving a Facebook AccessToken. If successful, I want to return the AccessToken string, if not I want to return an error message. These are both strings, so no problem. But when checking the return value on the calling side of the code, how can you do this effectively?

It’s like I need to return 2 values. In the case of a successful attempt, return = true, “ACESSCODEACXDJGKEIDJ”, or if it fails, return = false, “Ooops, there was an error” + ex.ToString();

Then checking the return value is easy (in theory). I could think of returning simply a true/false for return and then setting a Session variable for the strings.

What is a way to return multiple results from a method?

  • 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-28T06:12:08+00:00Added an answer on May 28, 2026 at 6:12 am

    Create a Result class and return that instead…

    public class Result
    {
       public bool Success {get;set;}
       public string AccessToken {get;set;}
       public string ErrorMessage {get;set;}
    }
    
    
    public Result GetFacebookToken()
    {
       Result result = new Result();
    
       try{
          result.AccessToken = "FACEBOOK TOKEN";
          result.Success = true;
       }
       catch(Exception ex){
          result.ErrorMessage = ex.Message;
          result.Success = false;
       }
    
       return result;
    }
    

    Then you can call this code like…

    Result result = GetFacebookToken();
    
    if(result.Success)
    {
       //do something with result.AccessToken
    }
    else
    {
       //do something with result.ErrorMessage 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok.. So I'm trying to improve my SQL skills and have a question. Here
I'm currently trying to improve my PHP skills and I have a sample below
I'm trying to improve my TDD/OO skills and each time I try and use
Hello everyone I'm trying to improve my Java skills by solving some problems from
I'm trying to improve my web development skills. I'm already familiar enough with HTTP,
I am trying to improve the performance of a web application. I have metrics
I've been trying to improve the build times for my product. We're using continuous
I am trying to improve my skills in encryption and decryption, but there are
I am trying to learn and improve my javascript skills. A very helpful tool
I trying to improve a textbox that filters a gridview, by implementing an enhanced

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.