I know you don't usually want to catch & throw, because you're not adding new 
information. If you want to add new information, generally you should throw a 
new exception and include an InnerException. Here are some examples of 
situations you would want to catch and rethrow:

https://msdn.microsoft.com/en-us/library/0yd65esw.aspx



I also know you destroy the stack trace if you explicitly name the exception 
you're rethrowing. In order to preserve the stack, you should throw without any 
arguments.

https://msdn.microsoft.com/en-us/library/ms182363.aspx



I know the difference between a debug build and release build, particularly 
with regards to optimizations and inlining.


In a debug build, the following code behaves as expected (prints out the full 
stack trace) on .NET, but doesn't print out the full stack on mono 4.2.3. I'm 
pretty sure it's not an expected behavior.

using System;

namespace FunWithRethrow
{
      class MainClass
      {
            public static void Main (string[] args)
            {
                  try {
                        Third ();
                  }
                  catch (Exception e) {
                        Console.WriteLine (e);
                  }
            }
            static void Third()
            {
                  Second ();
            }
            static void Second()
            {
                  try {
                        First();
                  }
                  catch {
                        throw;
                  }
            }
            static void First()
            {
                  throw new Exception ("Something said... Not good...");
            }
      }
}

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to