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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:32:50+00:00 2026-05-13T08:32:50+00:00

When is it appropriate to use a ThrowHelper method instead of throwing directly? void

  • 0

When is it appropriate to use a ThrowHelper method instead of throwing directly?

void MyMethod() {
    ...
    //throw new ArgumentNullException("paramName");
    ThrowArgumentNullException("paramName");
    ...
}
void ThrowArgumentNullException(string paramName) {
    throw new ArgumentNullException(paramName);
}

I’ve read that calling a ThrowHelper method (a method with the only purpouse of throwing an exception) instead of throwing directly should yield smaller bytecode.

This, and the obvious encapsulation (another layer of indirection), may be good reasons to not throw directly, at least in some scenarios.

Anyway, IMO the drawbacks are not insubstantial too.

  • A part of the (exceptional) control flow is hidden
  • Exceptions end up having a more cryptic stacktrace
  • the compiler (2.0) will not recognize that ThrowHelper calls are exit points from a method, hence some code-around is necessary.

My limited experience is that often the overall design gets worse.

int MyMethod(int i) {
    switch (i) {
        case 1:
            return 1;
        default:
            ThrowMyException();
    }
    return 0; // Unreachable (but needed) code
 }

This may partly be a matter of personal taste. Anyway what are your personal guidelines about this issue? Do you find it is a good idea to use ThrowHelpers for all those common tasks like method param validation (ThrowArgumentNullException(paramName) and such)?
Am I missing something obvious on this issue?

Btw I’m trying not to mix this issue with the validation issue, e.g. a method like:

ThrowIfNameIsNullOrEmpty(name);
  • 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-13T08:32:51+00:00Added an answer on May 13, 2026 at 8:32 am

    My default approach is to throw directly from the exceptional code branch.

    The DRY principle and the rule of 3 guides when I would wrap that in a method: if I find myself writing the same ‘throw’ code 3 or more times, I consider wrapping it in a helper method.

    However, instead of a method that throws, it’s much better to write a Factory Method that creates the desired Exception and then throw it from the original place:

    public void DoStuff(string stuff)
    {
        // Do something
    
        throw this.CreateException("Boo hiss!");
    }
    
    private MyException CreateException(string message)
    {
        return new MyException(message);
    }
    

    This preserves the stack trace.

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

Sidebar

Ask A Question

Stats

  • Questions 520k
  • Answers 520k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ended up righting my own little package that uses… May 16, 2026 at 8:48 pm
  • Editorial Team
    Editorial Team added an answer Wouldn't you just use the Google Calendar API? I don't… May 16, 2026 at 8:48 pm
  • Editorial Team
    Editorial Team added an answer In such cases enclose the variable in {} $id =… May 16, 2026 at 8:48 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Let's collect some tips for evaluating the appropriate use of global.asax.
What is the difference between std::runtime_error and std::exception ? What is the appropriate use
When is it appropriate to use a block comment at the beginning of methods,
I wonder why I should use: puts In folder #{File.join ENV[HOME], projects} Instead of:
I'm trying to use a pipelined function to save on time and reduce redundancy
I use ComboBox.ItemsSource=[some data collection] to bind data to the control. I want to
I want to use order by with union in mysql query. I am fetching
I have a the following use case where I'm receiving a message via JMS
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
I've used ConfigParser for quite a while for simple configs. One thing that's bugged

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.