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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:46:36+00:00 2026-05-23T23:46:36+00:00

I had a discussion today about refactoring this (#1) public void MyFunc(object myArgument) {

  • 0

I had a discussion today about refactoring this (#1)

public void MyFunc(object myArgument)
{
    if(myArgument == null)
        throw new ArgumentNullException("myArgument");
....

With this (#2)

//inside a shared assembly in a class called Guard
public static void AgainstArgumentNull(object obj, string message)
{
    if (obj == null)
        throw new ArgumentNullException(message);
}

public void MyFunc(object myArgument)
{
    Guard.AgainstArgumentNull(myArgument, "myArgument");
....

My intuition was that #1 was better for the following reasons:

  1. #1 is simpler than #2 in the sense that it requires no knowledge of Util library, just basic c# knowledge
  2. #1 will not remove the resharper ability to rename the string passed to ArgumentNullException constructor.
  3. #2 will increase the dependencies for the code (must have access to the dll containing the dll)
  4. The stacktrace will not be the same for #2 as it would be for #1

My questions here are:
Is my intuition correct?
Could the fact that we are throwing the exception from another assembly not become trouble in some scenarios?

  • 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-23T23:46:37+00:00Added an answer on May 23, 2026 at 11:46 pm

    For this particular case, you shouldn’t be using Guard anyway. You should be using Code Contracts.

    Contract.Requires(myArgument != null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I had a discussion with a colleague about nested functions in Javascript: function
Today we had a discussion at the office about UI elements in the required
I am pretty sure about my answer but today had a discussion with my
I just had a discussion today with some coworkers about python's db-api fetchone vs
I had a discussion this morning with a colleague about static variable initialization order.
Today at work I had a discussion with my co-workers and my boss about
I had a discussion with a developer earlier today re identifying TCP packets going
A discussion happened today where a grid containing data, which ultimately had data attached
I had a discussion a few weeks back with some co-workers on refactoring, and
I had a discussion with a colleague at work, it was about SQL queries

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.