简体   繁体   中英

Code will not run past exception VS2012

I have a try catch statement and when the code goes to throw the exception, it will not run past this point.

I press F5/F10 and the code keeps running the same line of code.

Is this to do with a setting in VS2012?

Calling code:

       if (!string.IsNullOrEmpty(connections.xmlconSIPPPremium))
                    {
                        try
                        {
                            DataTable dt = GetUtilityFiles(connections.xmlconSIPPPremium);
                            foreach (DataRow dr in dt.Rows)
                            {
                                File.WriteAllBytes(_rootDirectory + @"\" + dr["UtilityName"], (byte[])dr["UtilityBytes"]);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

                    }
                    else if (!string.IsNullOrEmpty(connections.xmlconSSASPremium))
                    {
                        try
                        {
                            DataTable dt = GetUtilityFiles(connections.xmlconSSASPremium);
                            foreach (DataRow dr in dt.Rows)
                            {
                                File.WriteAllBytes(_rootDirectory + @"\" + dr["UtilityName"], (byte[])dr["UtilityBytes"]);
                            }
                        }
                        catch(Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

                    }
                }

Issue:

    private DataTable GetUtilityFiles(string strCon)
    {
        DataTable dt = new DataTable();

        using (SqlConnection con = new SqlConnection(strCon))
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand("[dmm].[vertUtility_Select]", con))
                {
                    SqlDataAdapter sda = new SqlDataAdapter(cmd); 
                    sda.Fill(dt);         
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return dt;
        }
    }

Thanks!

Is it just that you want to switch off the "exception assistant"?

Tools -> options -> Debugging -> Enable the exception assistant [unchecked]

Then the exceptions won't stop execution.

Hope this helps!

When debugging there is indeed a setting in VS2012 how to you want to handle exceptions. Check under Debug -> Exceptions...

When you have the exception checked as "Thrown" the debugger will stop at that exception. Read more about "First chance exceptions": What is a "first chance exception"?

Read more about Exception handling in VS2012: http://msdn.microsoft.com/query/dev11.query?appId=Dev11IDEF1&l=EN-US&k=k(vs.debug.exceptions);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.0);k(DevLang-csharp)&rd=true

Also, when debugging, and you get the Exception assistand dialog, you can uncheck the option to break when that specific exception occurs.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM