Last active
May 23, 2017 14:11
-
-
Save mkropat/afc501468d669c97f027b52c3adc10b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArtificialStackTraceException : Exception | |
{ | |
public ArtificialStackTraceException( | |
bool shouldIncludeFileInfo = true, | |
string message = "Artificial exception used to generate a stack trace." | |
) : base(message) | |
{ | |
var stackTrace = new System.Diagnostics.StackTrace(shouldIncludeFileInfo); | |
StackTrace = stackTrace.ToString(); | |
} | |
public override string StackTrace { get; } | |
public override string ToString() | |
{ | |
return $"{nameof(ArtificialStackTraceException)}:{Environment.NewLine}{StackTrace}"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Query Kind="Program" /> | |
public class ArtificialStackTraceException : Exception | |
{ | |
public ArtificialStackTraceException( | |
bool shouldIncludeFileInfo = true, | |
string message = "Artificial exception used to generate a stack trace." | |
) : base(message) | |
{ | |
var stackTrace = new System.Diagnostics.StackTrace(shouldIncludeFileInfo); | |
StackTrace = stackTrace.ToString(); | |
} | |
public override string StackTrace { get; } | |
public override string ToString() | |
{ | |
return $"{nameof(ArtificialStackTraceException)}:{Environment.NewLine}{StackTrace}"; | |
} | |
} | |
void Main() | |
{ | |
new XElement("LINQPad.HTML", new XElement("h3", "new Exception")).Dump(); | |
Foo(() => new Exception()).ToString().Dump(); | |
new XElement("LINQPad.HTML", new XElement("h3", "Try...catch")).Dump(); | |
Foo(() => | |
{ | |
try | |
{ | |
throw new Exception(); | |
} | |
catch (Exception ex) | |
{ | |
return ex; | |
} | |
}).ToString().Dump(); | |
new XElement("LINQPad.HTML", new XElement("h3", "new ArtificialStackTraceException")).Dump(); | |
Foo(() => new ArtificialStackTraceException()).ToString().Dump(); | |
} | |
Exception Foo(Func<Exception> generateException) | |
{ | |
return Bar(generateException); | |
} | |
Exception Bar(Func<Exception> generateException) | |
{ | |
return Baz(generateException); | |
} | |
Exception Baz(Func<Exception> generateException) | |
{ | |
return generateException(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment