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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:32:33+00:00 2026-05-15T09:32:33+00:00

I have application reads in data from text file. Recently I realized that I

  • 0

I have application reads in data from text file. Recently I realized that I should make a data checker for the data in the text file, to see if I can display/handle it correctly.

Basically at the moment all the checker does is see if data is in the correct format, i.e. double is a double, int is int, etc… And if it isn’t I’m throwing an exception.

Like so:

private static string CheckDouble(string doublevar)
        {
            double tryParseDoubleResult;
            var tryParseDouble = double.TryParse(doublevar, out tryParseDoubleResult);

            if (tryParseDouble)
            {
                return doublevar;
            }

            throw new Exception("Invalid data found. Cannot open.");
        }

Which would be great. Except for the following:

  • I built this in Win 7 Environment in VS 2008.
  • I’ve tested in Win7/ XP
  • When running in Win7 – the exception does not throw. I can even see that it should have, as I display the data it loads into a listbox in the app, but after loading the list is blank. If I step through the code line by line to the item where there is bad data, I can see the exception throw. But not in Debug if not debugging line by line, and not in Release either.
  • In XP the exception throws as expected.

This is obviously a problem having the application run in a state where there is problem with the data but no indication to user and it should not have let the user get this far IF there was a problem with the data.

Why isn’t the exception throwing in Win7?


edit:

I think maybe the exception is being swallowed as I only see it thrown when stepping through line by line. What is the best way to check if it is being swallowed? Just follow my apps execution and look for a Try block? (It still doesn’t exactly make sense when it throws properly in XP already, however…)

As a bit of extra, I have a start up window with 3 buttons. One is Open button. From here I open the data file to process.

var w = new Window1();
w.Show();

//At this point, FormLoad of all tabitems inside window1 execute, where the exception SHOULD throw. And in fact when it happens, nothing is thrown but the execution jumps from the line where the exception should throw to the line below Close(); and the next window loads but one screen out of three is empty because of the exception thrown because of the data.

Close();

edit1:

The class where the exception is thrown is Singleton, I don’t know if this has anything to do with the problem…

edit2:

After several days further investigation, I’m still at a lost to why this is happening. Addressing the questions: yes I know I should make my own custom exception class. But this doesn’t change what is happening here. I cannot find a try catch higher up the stack. I have an exception handler where if an exception is thrown in the application, it Environment.Exit(1); then logs the exception to text file. I have taken the exception handler out completely and yet still see the same behaviour.

It is not due to regional settings problem…

And anyway, all aside, this still does not explain why the exception is thrown as intended in XP (and the app crashes and logs exception to file) whereas in Win7 – the exception is ignored and execution continues.

  • 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-15T09:32:33+00:00Added an answer on May 15, 2026 at 9:32 am

    First, you really should be throwing your own exceptions. System.Exception is the top-level exception from which all exceptions inherit. Consider creating a DataFormatException, for example – and throwing that.

    Next, it sounds like you are likely catching System.Exception someone lower in the stack that is swallowing this exception. Again, it would be ideal if you only catch System.Exception at the lowest point in the stack for that thread, and use that as a catch-all for the whole application. In other places in your code, you should catch the exceptions that expect to happen. For example, the caller of your method should only trying to catch DataFormatException and ArgumentException (which you should throw if “doublevar” is null or empty). For example:

    /// <summary>
    /// Checks to see if the specified value is a double.
    /// </summary>
    /// <param name="valueToCheck">The value to check.</param>
    /// <exception cref="ArgumentException">If <paramref name="valueToCheck"/>
    /// is null or empty.</exception>
    /// <exception cref="DataFormatException">If <paramref name="valueToCheck"/>
    /// could not be parsed as a valid double.</exception>
    private static double CheckDouble(string valueToCheck)
    {
        if (string.IsNullOrEmpty(valueToCheck))
            throw new ArgumentException("Argument 'valueToCheck' cannot be null or empty.", "valueToCheck");
    
        double result;
    
        if (double.TryParse(valueToCheck, out result))
        {
            return result;
        }
    
        throw new DataFormatException("Value '" + valueToCheck + "' could not be parsed as a double.");
    }
    

    Hope that helps…

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

Sidebar

Related Questions

I have an application that reads a CSV file with piles of data rows.
I have an application that reads lines from a file and runs its magic
I have a basic C# console application that reads a text file (CSV format)
I have an application that reads a table from a database. I issue an
I have an application that reads a database and outputs alerts to any dependencies
I have an ASP.NET web application which does the following: Reads an Excel file.
I have created a small application which opens,reads and creates Excel files. The app
System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to
I have read in Patterns of Enterprise Application Architecture that a Unit Of Work
I am using VS2008 to develop a WinForms 2.0 application. I have read about

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.