-1

I am getting this unhandled exception error shown: See screen shot.

enter image description here

I am getting this error only when I run with Ctrl+ F5 and not in F5(debug mode). Not sure if this is helpful, my computer is a windows 7- 64bit and running a 32 bit build

According to this discussion: How can I get WinForms to stop silently ignoring unhandled exceptions?, adding Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException) it wll cause Windows to ignore the error.

EDIT: frmPlant_Load Event

public partial class frmPlant : Form
    {
        DatabaseConnection _DbConnection = new DatabaseConnection();
        string conString = ConfigurationManager.ConnectionStrings["RVESTConnString"].ConnectionString;
        SQLQueries _SQlQueries = new SQLQueries();
        DataSet ds;
        SQLiteDataAdapter da;
       static DataTable gdt;
        int gSelectedPlant;
        string gSelectedPlantName = "";
        bool ignoreSelChg = false;
        bool DataDirty = false;
    public frmPlant()
        {
            InitializeComponent();        
        }
        public frmPlant(int sSelectedPlant)
        {
            InitializeComponent();           
        }
        private void frmPlant_Load(object sender, EventArgs e)
        {

            ds = FillData();
            gdt = ds.Tables[0];
            bindingSource1.DataSource = gdt;
            dataGridView1.DataSource = bindingSource1;
            gSelectedPlant = StaticClass.GlobalValue;
            dataGridView1.AutoGenerateColumns = true;
            dataGridView1.Columns["PlantId"].Visible = false;
            dataGridView1.Columns["NSSS_Design"].Width = 70;          
        }
        private DataSet FillData()
        {
            ignoreSelChg = true;
            SQLiteConnection con = new SQLiteConnection(conString);
            DataSet dPlant;
            try
            {
                con.Open();
                SQLiteCommand cmd = new SQLiteCommand("select * from Plant", con);
                da = new SQLiteDataAdapter("select * from Plant", con);
                dPlant = new DataSet();
                da.Fill(dPlant, "plant"); 

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return dPlant;
        }

I should also add another concern: When I say continue here in the dialog, it works fine but leaves a background process running. I have to manually go and kill it in the task manager

Question: Suppose I add this line in the Program.cs, will it ignore ANY- even genuine errors which need to be fixed?

More Code: This dialog pops up on button click on the second screen- Initial Setup screen . The first being a splash screen. Initial setup takes me to the Plant form

Here's the code for the initial setup screen

     public partial class frmInitialSetUp : Form
    {
        public frmInitialSetUp()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Program.fPlant = new frmPlant();
            Program.fPlant.Show();
            this.Hide();
        }

        private void frmInitialSetUp_Load(object sender, EventArgs e)
        {
            Program.LoadAllForms();   
        }
    }
}
Program.cs
      static public void LoadAllForms()
        {
            try
            {
                Program.fInitialSetUp = new frmInitialSetUp();
                Program.fPlant = new frmPlant();
                Program.frm*** = new frm***();
                Program.frm*** = new frm***();
                Program.frm*** = new frm***();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

On button click on the

Community
  • 1
  • 1
user575219
  • 2,346
  • 15
  • 54
  • 105
  • 4
    Which exceptions do you consider "need to be fixed" and which do you consider harmless? A `NullReferenceException` sounds like a bug to me. – C.Evenhuis Jun 02 '12 at 07:17
  • Given the error message, i think it is better to find and remove the exception, not to ignore it. – Steve Jun 02 '12 at 07:18
  • @Steve, @ C.Evenhuis: Then y is the bug not visible in F5mode. – user575219 Jun 02 '12 at 07:19
  • 1
    Could you show the code of RVEST.frmPlant.frmPlant_Load event? – Steve Jun 02 '12 at 07:23
  • 1
    The debugger actually changes some things here: the short answer is: you're doing something in Load that is erroring. This is a big big problem - but it works differently with/without the debugger. We can't tell you what without seeing your Load. – Marc Gravell Jun 02 '12 at 07:27
  • Please see edit. I have the code posted in the question. THanks – user575219 Jun 02 '12 at 07:33
  • 1
    Remove the `throw ex` in FillData. Let's see if the exception changes (Rethrowing in that way changes the stack trace) – Steve Jun 02 '12 at 07:45
  • I tried but didn't make any difference – user575219 Jun 02 '12 at 07:48
  • Sorry, I need to explain better, remove **all of the catch handler**. If for some reason the FillData throws, a catch handler, will swallow the exception, the dataset returns as null and your form_load broke with a meaningless exception – Steve Jun 02 '12 at 07:54
  • Why you create two copies of frmPlant? – Steve Jun 02 '12 at 08:05
  • @Steve: Program.fPlant = new frmPlant(); Program.fPlant.Show(); this.Hide(); Here in this piece I deleted the line Program.fPlant = new frmPlant() because, it is loading all forms in Program.LoadAllForms. Yet, the problem remains – user575219 Jun 02 '12 at 08:18
  • possible duplicate of [VS2010 does not show unhandled exception message in a WinForms Application on a 64-bit version of Windows](http://stackoverflow.com/questions/4933958/vs2010-does-not-show-unhandled-exception-message-in-a-winforms-application-on-a) – Hans Passant Jun 02 '12 at 13:16

1 Answers1

1

Enclosed the frmload in a try { } catch(unhandledexception ex) {} and ran it in debug mode This time the debugger caught it. It was a small problem with datagridview columns

user575219
  • 2,346
  • 15
  • 54
  • 105