Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. "Hiding" functions from StackTrace

"Hiding" functions from StackTrace

Scheduled Pinned Locked Moved C#
csharphtmldotnetcomtesting
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bernhard Hiller
    wrote on last edited by
    #1

    When some exception occurs in a class of the .Net framework, we see the public function of a public class called by our code only, the further details (private functions, or even non-public classes) used by the public function are hidden in the StackTrace 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 an Assert fails, I get a long StackTrace 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 and ExceptionAssert in the StackTrace?

    Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

    OriginalGriffO L 2 Replies Last reply
    0
    • B Bernhard Hiller

      When some exception occurs in a class of the .Net framework, we see the public function of a public class called by our code only, the further details (private functions, or even non-public classes) used by the public function are hidden in the StackTrace 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 an Assert fails, I get a long StackTrace 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 and ExceptionAssert in the StackTrace?

      Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • B Bernhard Hiller

        When some exception occurs in a class of the .Net framework, we see the public function of a public class called by our code only, the further details (private functions, or even non-public classes) used by the public function are hidden in the StackTrace 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 an Assert fails, I get a long StackTrace 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 and ExceptionAssert in the StackTrace?

        Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups