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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:15:37+00:00 2026-06-05T18:15:37+00:00

If I am writing an API that takes an int parsed from a string,

  • 0

If I am writing an API that takes an int parsed from a string, is it a good idea to seperate the parse method from the method that would do something with the “out” value?

My reason for thinking yes is that the code will be more clear. E.g. if I get an exception related to the parse, I can say in the stack “ah yes, that would be the top method called Parse() obviously!” before even looking at the codebase. I believe null is the wrong choice as it could introduce bugs by other developers who do not understand the technical decisions made (though I document this religously).

However, in a method that is 5 levels deep in the stack, how could I “Relay” an error string message?

Thanks

  • 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-05T18:15:40+00:00Added an answer on June 5, 2026 at 6:15 pm

    In order to relay the error string message, create an exception and use the “throw” keyword.

    As for separating the parse method, is this what you are asking for?

    int myInt;
    if(!Int32.TryParse(inputString, out int myInt))
        throw new System.ArgumentException("Invalid Argument", "inputString");
    
    methodThatUsesInt(myInt);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application using twitter api and that involves writing a method
I'm writing some code against a C++ API that takes vectors of vectors of
I'm working with a Ruby API that takes a series of boolean switches, something
I'm writing an API on Android that will be used by an existing application,
I am writing a WCF Rest API that provides CRUD functionality to an entity
Hey--I'm writing a basic Rails app that uses the digg API. I'm trying to
I have an application I'm writing for Windows 8/WinRT that uses the StreamSocket API
I'm writing FFI to pdflib. Pdflib C API has lots of functions that return
I'm currently writing a Rails 3 app that uses the google maps API (v3)
Can anyone suggest a pattern that can be used for writing a JavaScript API

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.