Assert( #if RESHARPER_ATTRIBUTES [JetBrains.Annotations.AssertionCondition(JetBrains.Annotations.AssertionConditionType.IS_TRUE)] #endif [DoesNotReturnIf(false)] bool condition, string whyThisShouldNeverHappen, string detailMessage) { // Early out avoids some slower code below (mostly the locking done in ThrowInsteadOfAssert). if (condition) { return; } #if ASSERTIONS_TRACE if (!condition) { if (Diagnostics.ThrowInsteadOfAssert) { string assertionMessage = "ASSERT: " + whyThisShouldNeverHappen + " " + detailMessage + " "; AssertException e = new AssertException(assertionMessage); tracer.TraceException(e); throw e; } StringBuilder builder = new StringBuilder(); builder.Append("ASSERT: "); builder.Append(whyThisShouldNeverHappen); builder.Append("."); if (detailMessage.Length != 0) { builder.Append(detailMessage); builder.Append("."); } // 2 to skip this method and Diagnostics.StackTace builder.Append(Diagnostics.StackTrace(2)); tracer.TraceError(builder.ToString()); } #else if (Diagnostics.ThrowInsteadOfAssert) { string assertionMessage = "ASSERT: " + whyThisShouldNeverHappen + " " + detailMessage + " "; throw new AssertException(assertionMessage); } System.Diagnostics.Debug.Fail(whyThisShouldNeverHappen, detailMessage); #endif }
internal AssertException(string message) : base(message) { this.stackTrace = Diagnostics.StackTrace(3); }
/// <summary> /// Calls the base class with message and sets the stack frame. /// </summary> /// <param name="message">Repassed to the base class.</param> internal AssertException(string message) : base(message) { // 3 will skip the assertion caller, this method and AssertException.StackTrace StackTrace = Diagnostics.StackTrace(3); }