[Mono-dev] Bug preserving stack trace

Edward Ned Harvey (mono) edward.harvey.mono at clevertrove.com
Tue Jun 28 11:08:11 UTC 2016


Any responses?


> -----Original Message-----
> From: mono-devel-list-bounces at lists.ximian.com [mailto:mono-devel-list-
> bounces at lists.ximian.com] On Behalf Of Edward Ned Harvey (mono)
> Sent: Wednesday, June 22, 2016 7:59 AM
> 
> 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...");
>             }
>       }
> }


More information about the Mono-devel-list mailing list