"Hiding" functions from StackTrace
-
When some exception occurs in a class of the .Net framework, we see the
public function
of apublic class
called by our code only, the further details (private functions, or even non-public classes) used by the public function are hidden in theStackTrace
of the exception object, when the exception occurred somewhere down there. Now I have some functionality where I'd like to have such a feature, too: For testing, we use MS Test. I added some extensions, e.g. "ThrowsAssert
" (based on Asserting Exceptions in MSTest with Assert.Throws()[^]). When such anAssert
fails, I get a longStackTrace
like:bei TestUtilities.ExceptionAssert.OnNoExceptionThrown[T](String _customMessage) in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\C_TestUtilities\ExceptionAssert.cs:Zeile 29.
bei TestUtilities.ThrowsAssert.Throws[T](Action _task, String _expectedMessage, ExceptionMessageCompareOptions _messageOptions, ExceptionInheritanceOptions _inheritOptions, String _customMessage) in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\C_TestUtilities\ThrowsAssert.cs:Zeile 42.
bei MyAssembly.Tests.MyClassTests.MyFunctionTest() in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\MyAssemblyTests\MyClassTests.cs:Zeile 36.or even longer... Is there some way to "hide" all those functions of class
ThrowsAssert
andExceptionAssert
in the StackTrace?Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
-
When some exception occurs in a class of the .Net framework, we see the
public function
of apublic class
called by our code only, the further details (private functions, or even non-public classes) used by the public function are hidden in theStackTrace
of the exception object, when the exception occurred somewhere down there. Now I have some functionality where I'd like to have such a feature, too: For testing, we use MS Test. I added some extensions, e.g. "ThrowsAssert
" (based on Asserting Exceptions in MSTest with Assert.Throws()[^]). When such anAssert
fails, I get a longStackTrace
like:bei TestUtilities.ExceptionAssert.OnNoExceptionThrown[T](String _customMessage) in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\C_TestUtilities\ExceptionAssert.cs:Zeile 29.
bei TestUtilities.ThrowsAssert.Throws[T](Action _task, String _expectedMessage, ExceptionMessageCompareOptions _messageOptions, ExceptionInheritanceOptions _inheritOptions, String _customMessage) in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\C_TestUtilities\ThrowsAssert.cs:Zeile 42.
bei MyAssembly.Tests.MyClassTests.MyFunctionTest() in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\MyAssemblyTests\MyClassTests.cs:Zeile 36.or even longer... Is there some way to "hide" all those functions of class
ThrowsAssert
andExceptionAssert
in the StackTrace?Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
As far as I'm aware, the only way to hide methods from the stack trace is to get the compiler to
inline
them - since they are no longer called, they are no longer available to stack tracing. Unfortunately for you, there is no way that I know of to force the compiler to inline a method - you can force it to not inline, but the reverse does not apply. I understand that you can (in v4.5 and later) hint that you might like it inlined: MethodImplOptions Enum (System.Runtime.CompilerServices) | Microsoft Docs[^] using the AgressiveInlining field, but that is just a suggestion, not an order!Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
When some exception occurs in a class of the .Net framework, we see the
public function
of apublic class
called by our code only, the further details (private functions, or even non-public classes) used by the public function are hidden in theStackTrace
of the exception object, when the exception occurred somewhere down there. Now I have some functionality where I'd like to have such a feature, too: For testing, we use MS Test. I added some extensions, e.g. "ThrowsAssert
" (based on Asserting Exceptions in MSTest with Assert.Throws()[^]). When such anAssert
fails, I get a longStackTrace
like:bei TestUtilities.ExceptionAssert.OnNoExceptionThrown[T](String _customMessage) in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\C_TestUtilities\ExceptionAssert.cs:Zeile 29.
bei TestUtilities.ThrowsAssert.Throws[T](Action _task, String _expectedMessage, ExceptionMessageCompareOptions _messageOptions, ExceptionInheritanceOptions _inheritOptions, String _customMessage) in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\C_TestUtilities\ThrowsAssert.cs:Zeile 42.
bei MyAssembly.Tests.MyClassTests.MyFunctionTest() in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\MyAssemblyTests\MyClassTests.cs:Zeile 36.or even longer... Is there some way to "hide" all those functions of class
ThrowsAssert
andExceptionAssert
in the StackTrace?Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
Take the "stack trace", run it through a "string reader", and eliminate the entries you don't want (via a class or method "name" related to the exception). I do all my "trace filtering" in the
Application_DispatcherUnhandledException
event handler. At that point, I can even "continue execution" via "e.handled" (if the situation calls for it).
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal