How do I re-throw an exception back to the debugger?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BeemerBiker
    New Member
    • Jul 2008
    • 87

    How do I re-throw an exception back to the debugger?

    I am trying my hand at throwing custom exceptions. Unfortunately, while my code to catch them does work, all the other exceptions go thru my exception handler. How do I let the exception continue on so that the VS debugger stops at the line of code that caused the problen and not in my custom catch routine which is only looking for a few things?

    Code:
                try
                {
                    SolveProblem();
                }
                catch (Exception e)
                {
                    if (e.Message == "Completed")
                    {
                        Environment.Exit(0);
                    }
                    else throw (new (WhateverWorksGoesHere));
                }
    I tried IOException but that didnt work. I want the VS debugger to handle all exceptions like it normally does and not stop in my above code with the message "Exception Unhandled"

    I did spend some time googleing this but there was too much googlenoise.

    Thanks for looking!
  • Joseph Martell
    Recognized Expert New Member
    • Jan 2010
    • 198

    #2
    You can throw the same exception that you caught. Basically:

    Code:
    try
    {
        SolveProblem();
    }
    catch (Exception e)
    {
        if (e.Message == "Completed")
        {
            Environment.Exit(0);
        }
        else
            throw e;
    }

    Comment

    • Christian Binder
      Recognized Expert New Member
      • Jan 2008
      • 218

      #3
      Look at Visual Studio menu Debug and Exceptions.
      There you can set, that the debugger stops even when the exceptions are handled (and you can choose at which exceptions you want your debugger to stop).

      Comment

      • BeemerBiker
        New Member
        • Jul 2008
        • 87

        #4
        Didnt work worth a hoot, got a null reference as shown


        After commenting out my custom throw-catch, I got the following useful stuff

        Comment

        • peochei
          New Member
          • Oct 2010
          • 12

          #5
          Did you check "Thrown" checkbox for whole "Common Language Runtime Exceptions"?

          Comment

          • Christian Binder
            Recognized Expert New Member
            • Jan 2008
            • 218

            #6
            I know what you're looking for.
            As I told you in my previous post, did you set the debugger to stop on a NullReferenceEx ception? Maybe you missed to select this option.

            Maybe there are two check-boxes to select for NullReferenceEx ception (that' beneath Common Language Runtime Exceptions / System, you have to select "Thrown" or something like this in Debug--Exceptions menu.

            This should do exactly what you want to do.

            Comment

            • BeemerBiker
              New Member
              • Jul 2008
              • 87

              #7
              missing an assembly when all exceptions thrown

              I changed the exceptions as suggested, but then had a problem with XML Serialization as shown below. Googleing I see where this may be a bug with VS2008.

              With exceptions thrown, the serializer fails to work as shown here


              With exceptions turned off, the serializer runs ok.


              There is probably one exception that is thrown that should not be thrown. I will go thru the list and find which one it is to allow the serializer to run.

              Comment

              • Christian Binder
                Recognized Expert New Member
                • Jan 2008
                • 218

                #8
                There might be an exeption thrown within the .net-framework. But you can step over it when it shows up. Alternatively you can disable this exeptions in the Exceptions-Dialog. Just search for BindingFailure.
                Also I don't think, it's necessary to have all exceptions enabled, I just check Common Language Runtime Exceptions when I need it, because the other exception-types are very rare.

                Comment

                Working...