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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:47:11+00:00 2026-05-13T05:47:11+00:00

I am actually working on a Framework development, which means require a really strong

  • 0

I am actually working on a Framework development, which means require a really strong coding methodology.

I am facing a problem where I do not know which System.Exception derivated class I need to throw. Basically the case is when I have a class with fields that can be optionnaly initialized by the constructor and that have methods using these fields. Which exception must I throw if the user did not initialized these fields? (which means they are null)

Here is an example:

public class MyConnection
{
    private Uri endpointUri;

    public Uri EndpointUri
    {
        get
        {
            return this.endpointUri;
        }

        set
        {
            this.endpointUri = value;
        }
    }

    public MyConnection()
    {
    }

    public MyConnection(Uri endpointUri)
    {
        this.endpointUri = endpointUri;
    }

    public FileStream GetFile()
    {
        if (this.endpointUri != null)
        {
            // My doer methods
        }
        else
        {
            throw new TheExceptionINeedToThrow("endpointUri", ...);
        }                
    }
}

Note that I have been reading the whole “Framework Design Guidelines” chapter concerning exception handling and throwing and that I did not found any solution fitting this exact case. Or maybe I misunderstood something …

Thanks for your help.

EDIT : The fact that I provide an empty constructor seems a bit confusing regarding my problem but it is completely voluntary. In some objects that have to comply with a range of different states that cannot be duplicated in multiple objects it is sometimes useful.

  • 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-13T05:47:12+00:00Added an answer on May 13, 2026 at 5:47 am

    Throw InvalidOperationException:

    The exception that is thrown when a method call is invalid for the object’s current state.

    Note that the null reference isn’t being passed into the method – it’s already there when the method is called – so it’s the object’s current state which is invalid, not an argument.

    However, it would be better to prevent the object from being created in this way to start with, if at all possible – does it have to be a writable property? Would you ever want an instance which did have a null endpoint URI?

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

Sidebar

Related Questions

actually i'm working with .Net Framework 3.5, so i have all these nice little
I'm working with a PHP MVC Framework. Works really well. I like the separation
I'm actually working on a web application coded in php with zend framework. I
Context I am working on a pretty complex web site framework which includes a
I'm actually working on a job for school and I try to create a
Actually I am working on this for the last 3 or 4 weeks but
Actually ,i am working on a livechat application its works fine.This application is tabbed
Actually I'm working with BufferedImages, that provide me pixel values in int type. Do
I am working on an Apple MDM server, and actually it is working fine.
I've got an ASP document that 5 years old. Actually I'm working with PHP

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.