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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:04:31+00:00 2026-06-12T01:04:31+00:00

I just recently started looking into exceptions and best practices for their use and

  • 0

I just recently started looking into exceptions and best practices for their use and I wonder what is the correct way of doing this:

Suppose there is a method with multiple arguments. And there are multiple overloads for this method with less parameters, which call the main implementation by providing default values.

Do I validate all arguments in every overload?

public string Translate(string text)
{
    if (String.IsNullOrEmpty(text))
        throw new ArgumentNullException();

    return Translate(text, "english");
}

public string Translate(string text, string language)
{
    if (String.IsNullOrEmpty(text))
        throw new ArgumentNullException();

    // Do the rest of the work
    // ...
}

Do I rethrow the exceptions?

public string Translate(string text)
{
    try
    {
        return Translate(text, "english");
    }
    catch
    {
        throw;
    }
}

public string Translate(string text, string language)
{
    if (String.IsNullOrEmpty(text))
        throw new ArgumentNullException();

    // Do the rest of the work
    // ...
}

Or do I completely drop exceptions and try/catch blocks in the overload?

public string Translate(string text)
{
    return Translate(text, "english");
}

public string Translate(string text, string language)
{
    if (String.IsNullOrEmpty(text))
        throw new ArgumentNullException();

    // Do the rest of the work
    // ...
}

Also, how would the documentation of the two methods look like?

(Using C# XML comments. Especially where I put the <exception> elements.)


I do realize that this is a minor topic, still, I keep wondering everytime I encounter this kind of situation (which is actually quite often).

  • 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-12T01:04:32+00:00Added an answer on June 12, 2026 at 1:04 am

    Optional arguments solves this in a way, then you have only one method:

    public string Translate(string text, string language="english")
    

    There are some quirks with optional arguments that are good to know about.

    the default values are “baked into” the calling code. […]
    The issue this can cause is the same for exposing public consts – if
    you change the default values in a library, but don’t recompile the
    calling code, then the calling code will still call your method(s)
    with the old default values. This is definitely something you need to
    consider when designing APIs using optional parameters.

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

Sidebar

Related Questions

I've just recently started looking into the details of which events fire when in
I have just recently started using ReSharper and am looking for a way of
I just recently started looking into WatiN and was following the example from http://www.codeproject.com/KB/aspnet/WatiN.aspx
I just recently started diving into Real World Haskell and the book provides some
I am little more than beginner PHP programmer and just recently started to use
I have recently started looking into MQs and I had some very basic questions,
I just recently started toying with output buffering and seem to have run into
I just recently started learning and using the ADO.NET Entity Framework and ran into
I just recently started looking at dump files to help me analyze crashes of
I've just recently started using hibernate and so I apologize if this is a

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.