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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:46:15+00:00 2026-06-01T08:46:15+00:00

Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I

  • 0

Lets say I have this code:

public void MyMethod(string Data, List<string> InputData)
{
  //I would assume throwing an exception for nulls would be correct
  if (String.IsNullOrWhiteSpace(Data) || InputData == null)
    throw new ArgumentNullException("Oops");

  if (InputData.Count == 0) 
    //throw exception or use event to raise a problem
    //throw Exception("Empty List")
    //if (DisplayError != null)
    //  DisplayError("Empty List");
}

Now having a empty list is not an exceptional problem so I should cope with it elegantly. One way is to raise an event to notify the problem. Just makes me wonder why I dont just raise the event if the arguments are null.

What is the best practice in this type of issue?

EventHandler Example:

public class MyOtherClass
{
  public event Action<string,List<string>> ItFired;

  public void DoSomething()
  {
     if(ItFired != null)
       ItFired(myString, myList);
  }
}

public class AnotherClass
{
     public void DoSomething()
     {
           var otherclass = new MyOtherClass();
           var myClass = new MyClass();

           otherClass.ItFired += myClass.MyMethod;
     }

}
  • 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-01T08:46:17+00:00Added an answer on June 1, 2026 at 8:46 am

    If an empty list is not exceptional problem do not raise exception in that case. Exceptions are for exceptional cases. In this case you can just return some boolean (say) value, that indicates that function is not executed.

    If for the caller of that function that would be an exceptional case, then it (caller) will raise an exception.

    Good luck.

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

Sidebar

Related Questions

Lets say I have this code: public static void main(final String [] args) {
Lets say we have this code: class test_t { void* data; public: template <typename
Lets say we have these 2 sample code : public synchronized void getSomething(){ this.hello
Well lets say we have this c# code: public override void Write(XDRDestination destination) {
Lets say i have the following code private Func<T> _method; public void SetExecutableMethod<T>(Func<T> methodParam)
Let's say I have the following code: public void Inject(Form subform) { this.tabControl1.TabPages[1].Controls.Add(subform); this.Refresh();
Lets say I have this code: <?php class hello { var $greeting = hello;
Lets say we have this code: bool KeepGoing = true; DataInThread = new Thread(new
Possible Duplicate: How Do I Access This Variable? Lets say I have the code:
This is my main class code: public static void main(String[] args) { JFrame f=

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.