exception with no stack trace - how?

后端 未结 2 1539
故里飘歌
故里飘歌 2021-01-04 01:15

We have a service which will log unhandled exceptions at the app domain level (via Log4net).

We logged:

2014-01-28 16:49:19,636 ERROR [49] Fe

相关标签:
2条回答
  • 2021-01-04 01:39

    If you're receiving an exception but no corresponding stack trace then at some point an exception handler is probably evaluating the exception and re-throwing it incorrectly. For example, if you're doing a throw ex; you'll eat the stack trace that led to that point. To preserve the existing call stack you want to simply throw; Throwing exceptions best practices

    Note that the C# way is the opposite of the convention for the Java language, where you are supposed to throw ex; Java reference: Best Practice: Catching and re-throwing Java Exceptions

    0 讨论(0)
  • 2021-01-04 01:42

    I prefer to manage my exceptions with custom exceptions, If in your case you are using your own exceptions you can go the the class were you define them and override the stacktrace. e.g:

    public class YourCustomException: Exception
    {
        public YourCustomException() : base() { } //constructor
    
        public override string StackTrace 
        {
            get { return "Message instead stacktrace"; }
        }
    }
    
    0 讨论(0)
提交回复
热议问题