1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
namespace System.Diagnostics {
using System;
using System.Security.Permissions;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Diagnostics.Contracts;
using System.Diagnostics.CodeAnalysis;
// Class which handles code asserts. Asserts are used to explicitly protect
// assumptions made in the code. In general if an assert fails, it indicates
// a program
internal static class Assert
{
internal const int COR_E_FAILFAST = unchecked((int) 0x80131623);
private static AssertFilter Filter;
static Assert()
{
Filter = new DefaultFilter();
}
// Called when an assertion is being made.
//
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
internal static void Check(bool condition, String conditionString, String message)
{
if (!condition)
{
Fail (conditionString, message, null, COR_E_FAILFAST);
}
}
[ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
internal static void Check(bool condition, String conditionString, String message, int exitCode)
{
if (!condition)
{
Fail(conditionString, message, null, exitCode);
}
}
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Process, ResourceScope.Process)]
internal static void Fail(String conditionString, String message)
{
Fail(conditionString, message, null, COR_E_FAILFAST);
}
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Process)]
internal static void Fail(String conditionString, String message, String windowTitle, int exitCode)
{
Fail(conditionString, message, windowTitle, exitCode, StackTrace.TraceFormat.Normal, 0);
}
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Process)]
internal static void Fail(String conditionString, String message, int exitCode, StackTrace.TraceFormat stackTraceFormat)
{
Fail(conditionString, message, null, exitCode, stackTraceFormat, 0);
}
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Process)]
internal static void Fail(String conditionString, String message, String windowTitle, int exitCode, StackTrace.TraceFormat stackTraceFormat, int numStackFramesToSkip)
{
// get the stacktrace
StackTrace st = new StackTrace(numStackFramesToSkip, true);
AssertFilters iResult = Filter.AssertFailure (conditionString, message, st, stackTraceFormat, windowTitle);
if (iResult == AssertFilters.FailDebug)
{
if (Debugger.IsAttached == true)
Debugger.Break();
else
{
if (Debugger.Launch() == false)
{
throw new InvalidOperationException(
Environment.GetResourceString("InvalidOperation_DebuggerLaunchFailed"));
}
}
}
else if (iResult == AssertFilters.FailTerminate)
{
#if FEATURE_CORECLR
// We want to exit the Silverlight application, after displaying a message.
// Our best known way to emulate this is to exit the process with a known
// error code. Jolt may not be prepared for an appdomain to be unloaded.
Environment._Exit(exitCode);
#else
// This assert dialog will be common for code contract failures. If a code contract failure
// occurs on an end user machine, we believe the right experience is to do a FailFast, which
// will report this error via Watson, so someone could theoretically fix the
if (Debugger.IsAttached)
Environment._Exit(exitCode);
else
Environment.FailFast(message, unchecked((uint) exitCode));
#endif
}
}
// Called when an assert happens.
// windowTitle can be null.
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.Process)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern static int ShowDefaultAssertDialog(String conditionString, String message, String stackTrace, String windowTitle);
}
}
|