Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. I take exception to the way Visual Studio 2010 handles exceptions

I take exception to the way Visual Studio 2010 handles exceptions

Scheduled Pinned Locked Moved C#
csharphelpquestionvisual-studiotutorial
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Columbus MCSD
    wrote on last edited by
    #1

    This is a gripe and a question, maybe someone can help me Problem Scenario: I just upgraded to Visual Studio 2010 Professional. I noticed some wierd things happening and after troubleshooting came up with this scenario Create a C# Windows Form Application in Visual Studio 2005 Professional Create a C# Windows Form Application in Visual Studio 2010 Professional Identical code in each

    namespace WindowsFormsApplication2
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    //throw new Exception("test");
    }

        private void Form1\_Load(object sender, EventArgs e)
        {
            //throw new Exception("test");
        }
    }
    

    }

    Visual Studio 2005 uncomment the 'throw' statement in the Form1 constructor. Visual Studio will report the exception and halt the code. uncomment the 'throw' statement in the Form1_Load event handler. Visual Studio will report the exception and halt the code Visual Studio 2010 uncomment the 'throw' statement in the Form1 constructor. Visual Studio will report the exception and halt the code. uncomment the 'throw' statement in the Form1_Load event handler. Visual Studio silently aborts the method and continues running the code This means that, in VS2010, in order to stop on , for example, a System.NullReferenceException that I threw, I have to check the "Thrown" box in the Exceptions configuration (cntrl+shift+E). Doing this causes it to stop on *every* System.NullReferenceException, even ones that are swallowed by a try/catch block. I want VS2010 to act like 2005. Halt on any Exception that isn't explicitly delt with by a try/catch block, even Exceptions that I throw myself. I don't get why it will halt on an explicit throw in the Forms constructor, but silently abort the method when thrown in the event handler. I find myself constantly reconfiguring the Exceptions config screen when something unexpected occurs (usually when an exception happens that I don't know about) Am I doing something wrong or is this just something I need to adapt to?

    R L B 3 Replies Last reply
    0
    • C Columbus MCSD

      This is a gripe and a question, maybe someone can help me Problem Scenario: I just upgraded to Visual Studio 2010 Professional. I noticed some wierd things happening and after troubleshooting came up with this scenario Create a C# Windows Form Application in Visual Studio 2005 Professional Create a C# Windows Form Application in Visual Studio 2010 Professional Identical code in each

      namespace WindowsFormsApplication2
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      //throw new Exception("test");
      }

          private void Form1\_Load(object sender, EventArgs e)
          {
              //throw new Exception("test");
          }
      }
      

      }

      Visual Studio 2005 uncomment the 'throw' statement in the Form1 constructor. Visual Studio will report the exception and halt the code. uncomment the 'throw' statement in the Form1_Load event handler. Visual Studio will report the exception and halt the code Visual Studio 2010 uncomment the 'throw' statement in the Form1 constructor. Visual Studio will report the exception and halt the code. uncomment the 'throw' statement in the Form1_Load event handler. Visual Studio silently aborts the method and continues running the code This means that, in VS2010, in order to stop on , for example, a System.NullReferenceException that I threw, I have to check the "Thrown" box in the Exceptions configuration (cntrl+shift+E). Doing this causes it to stop on *every* System.NullReferenceException, even ones that are swallowed by a try/catch block. I want VS2010 to act like 2005. Halt on any Exception that isn't explicitly delt with by a try/catch block, even Exceptions that I throw myself. I don't get why it will halt on an explicit throw in the Forms constructor, but silently abort the method when thrown in the event handler. I find myself constantly reconfiguring the Exceptions config screen when something unexpected occurs (usually when an exception happens that I don't know about) Am I doing something wrong or is this just something I need to adapt to?

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      This sounds pretty odd. I'm sure there is no native difference in the way the two versions of Visual Studio handle exceptions in the debugger. Don't quite understand what you were saying about the exceptions configuration, but try this: In both environments, go to Exceptions configuration as you say (cntrl+shift+E). In both cases, there should be two columns of checkboxes 'Thrown' and 'User-unhandled'. If you've only got one column go to Tools->Options->Debugging->General and make sure 'Enable just my code' is chcked. Then, make sure the two columns in the two environments match.

      Regards, Rob Philpott.

      C 1 Reply Last reply
      0
      • R Rob Philpott

        This sounds pretty odd. I'm sure there is no native difference in the way the two versions of Visual Studio handle exceptions in the debugger. Don't quite understand what you were saying about the exceptions configuration, but try this: In both environments, go to Exceptions configuration as you say (cntrl+shift+E). In both cases, there should be two columns of checkboxes 'Thrown' and 'User-unhandled'. If you've only got one column go to Tools->Options->Debugging->General and make sure 'Enable just my code' is chcked. Then, make sure the two columns in the two environments match.

        Regards, Rob Philpott.

        C Offline
        C Offline
        Columbus MCSD
        wrote on last edited by
        #3

        Thanks for the reply :) You are correct when I'm talking about the "Exceptions Configuration" i'm referring to Dialog Box that you access via Cntrl+Alt+E (sorry I gave wrong shortcut in the original post) I verified using your method. Here's the strange bit. At home I have WIndows 7 64 bit, at work I have Windows 7 32 bit I just did a little test where i made a new C# WindowsApplication project. The work PC halted on the "throw new Exception()" in the Form1_Load handler, but the home PC did not.

        1 Reply Last reply
        0
        • C Columbus MCSD

          This is a gripe and a question, maybe someone can help me Problem Scenario: I just upgraded to Visual Studio 2010 Professional. I noticed some wierd things happening and after troubleshooting came up with this scenario Create a C# Windows Form Application in Visual Studio 2005 Professional Create a C# Windows Form Application in Visual Studio 2010 Professional Identical code in each

          namespace WindowsFormsApplication2
          {
          public partial class Form1 : Form
          {
          public Form1()
          {
          InitializeComponent();
          //throw new Exception("test");
          }

              private void Form1\_Load(object sender, EventArgs e)
              {
                  //throw new Exception("test");
              }
          }
          

          }

          Visual Studio 2005 uncomment the 'throw' statement in the Form1 constructor. Visual Studio will report the exception and halt the code. uncomment the 'throw' statement in the Form1_Load event handler. Visual Studio will report the exception and halt the code Visual Studio 2010 uncomment the 'throw' statement in the Form1 constructor. Visual Studio will report the exception and halt the code. uncomment the 'throw' statement in the Form1_Load event handler. Visual Studio silently aborts the method and continues running the code This means that, in VS2010, in order to stop on , for example, a System.NullReferenceException that I threw, I have to check the "Thrown" box in the Exceptions configuration (cntrl+shift+E). Doing this causes it to stop on *every* System.NullReferenceException, even ones that are swallowed by a try/catch block. I want VS2010 to act like 2005. Halt on any Exception that isn't explicitly delt with by a try/catch block, even Exceptions that I throw myself. I don't get why it will halt on an explicit throw in the Forms constructor, but silently abort the method when thrown in the event handler. I find myself constantly reconfiguring the Exceptions config screen when something unexpected occurs (usually when an exception happens that I don't know about) Am I doing something wrong or is this just something I need to adapt to?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Sardaan Frostreaver wrote:

          even ones that are swallowed by a try/catch block.

          Do you seriously write code that swallows exceptions in production?

          C 1 Reply Last reply
          0
          • L Lost User

            Sardaan Frostreaver wrote:

            even ones that are swallowed by a try/catch block.

            Do you seriously write code that swallows exceptions in production?

            C Offline
            C Offline
            Columbus MCSD
            wrote on last edited by
            #5

            While I appreciate what you're saying, in the interest of preventing a debate on exception handling, let's keep the scope in context

            L 1 Reply Last reply
            0
            • C Columbus MCSD

              While I appreciate what you're saying, in the interest of preventing a debate on exception handling, let's keep the scope in context

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              ok, thanks.

              1 Reply Last reply
              0
              • C Columbus MCSD

                This is a gripe and a question, maybe someone can help me Problem Scenario: I just upgraded to Visual Studio 2010 Professional. I noticed some wierd things happening and after troubleshooting came up with this scenario Create a C# Windows Form Application in Visual Studio 2005 Professional Create a C# Windows Form Application in Visual Studio 2010 Professional Identical code in each

                namespace WindowsFormsApplication2
                {
                public partial class Form1 : Form
                {
                public Form1()
                {
                InitializeComponent();
                //throw new Exception("test");
                }

                    private void Form1\_Load(object sender, EventArgs e)
                    {
                        //throw new Exception("test");
                    }
                }
                

                }

                Visual Studio 2005 uncomment the 'throw' statement in the Form1 constructor. Visual Studio will report the exception and halt the code. uncomment the 'throw' statement in the Form1_Load event handler. Visual Studio will report the exception and halt the code Visual Studio 2010 uncomment the 'throw' statement in the Form1 constructor. Visual Studio will report the exception and halt the code. uncomment the 'throw' statement in the Form1_Load event handler. Visual Studio silently aborts the method and continues running the code This means that, in VS2010, in order to stop on , for example, a System.NullReferenceException that I threw, I have to check the "Thrown" box in the Exceptions configuration (cntrl+shift+E). Doing this causes it to stop on *every* System.NullReferenceException, even ones that are swallowed by a try/catch block. I want VS2010 to act like 2005. Halt on any Exception that isn't explicitly delt with by a try/catch block, even Exceptions that I throw myself. I don't get why it will halt on an explicit throw in the Forms constructor, but silently abort the method when thrown in the event handler. I find myself constantly reconfiguring the Exceptions config screen when something unexpected occurs (usually when an exception happens that I don't know about) Am I doing something wrong or is this just something I need to adapt to?

                B Offline
                B Offline
                Bernhard Hiller
                wrote on last edited by
                #7

                Look at that link: http://blog.paulbetts.org/index.php/2010/07/20/the-case-of-the-disappearing-onload-exception-user-mode-callback-exceptions-in-x64/[^] Nice, isn't it?

                L C M 3 Replies Last reply
                0
                • B Bernhard Hiller

                  Look at that link: http://blog.paulbetts.org/index.php/2010/07/20/the-case-of-the-disappearing-onload-exception-user-mode-callback-exceptions-in-x64/[^] Nice, isn't it?

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  Very interesting material. Thanks. :)

                  Luc Pattyn [My Articles] Nil Volentibus Arduum

                  1 Reply Last reply
                  0
                  • B Bernhard Hiller

                    Look at that link: http://blog.paulbetts.org/index.php/2010/07/20/the-case-of-the-disappearing-onload-exception-user-mode-callback-exceptions-in-x64/[^] Nice, isn't it?

                    C Offline
                    C Offline
                    Columbus MCSD
                    wrote on last edited by
                    #9

                    That's it! Here's the C# signatures to implement his solution

                        // definition
                        public const uint PROCESS\_CALLBACK\_FILTER\_ENABLED = 1;
                        
                        \[DllImport("kernel32.DLL")\]
                        public static extern bool SetProcessUserModeExceptionPolicy(uint dwFlags);
                        \[DllImport("kernel32.DLL")\]
                        public static extern bool GetProcessUserModeExceptionPolicy(ref uint lpFlags);
                    
                        // usage
                        uint dwFlags = 0;
                        if (StormWindows.Win32Api.GetProcessUserModeExceptionPolicy(ref dwFlags))
                        {
                            SetProcessUserModeExceptionPolicy(dwFlags & ~PROCESS\_CALLBACK\_FILTER\_ENABLED);
                        }
                    
                    1 Reply Last reply
                    0
                    • B Bernhard Hiller

                      Look at that link: http://blog.paulbetts.org/index.php/2010/07/20/the-case-of-the-disappearing-onload-exception-user-mode-callback-exceptions-in-x64/[^] Nice, isn't it?

                      M Offline
                      M Offline
                      MicroVirus
                      wrote on last edited by
                      #10

                      Thank you SO much for this link. I was, as the article described, pulling my hair out why and how a first-chance unhandled exception caused my program to silently crash in debug mode.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups