7using System.Diagnostics;
8using System.Runtime.InteropServices;
17 [StructLayout(LayoutKind.Sequential)]
18 internal readonly
struct ExceptionHandler : IEquatable<ExceptionHandler>
21 internal readonly
int m_exceptionClass;
22 internal readonly
int m_tryStartOffset;
23 internal readonly
int m_tryEndOffset;
24 internal readonly
int m_filterOffset;
25 internal readonly
int m_handlerStartOffset;
26 internal readonly
int m_handlerEndOffset;
27 internal readonly ExceptionHandlingClauseOptions m_kind;
29 public int ExceptionTypeToken
31 get {
return m_exceptionClass; }
36 get {
return m_tryStartOffset; }
41 get {
return m_tryEndOffset - m_tryStartOffset; }
44 public int FilterOffset
46 get {
return m_filterOffset; }
49 public int HandlerOffset
51 get {
return m_handlerStartOffset; }
54 public int HandlerLength
56 get {
return m_handlerEndOffset - m_handlerStartOffset; }
59 public ExceptionHandlingClauseOptions Kind
61 get {
return m_kind; }
81 public ExceptionHandler(
int tryOffset,
int tryLength,
int filterOffset,
int handlerOffset,
int handlerLength,
82 ExceptionHandlingClauseOptions kind,
int exceptionTypeToken)
86 throw new ArgumentOutOfRangeException(
"tryOffset",
string.Format(
"Non-negative number required."));
91 throw new ArgumentOutOfRangeException(
"tryLength",
string.Format(
"Non-negative number required."));
96 throw new ArgumentOutOfRangeException(
"filterOffset",
string.Format(
"Non-negative number required."));
99 if (handlerOffset < 0)
101 throw new ArgumentOutOfRangeException(
"handlerOffset",
string.Format(
"Non-negative number required."));
104 if (handlerLength < 0)
106 throw new ArgumentOutOfRangeException(
"handlerLength",
string.Format(
"Non-negative number required."));
109 if ((
long)tryOffset + tryLength > Int32.MaxValue)
111 throw new ArgumentOutOfRangeException(
"tryLength",
string.Format(
"Valid values are between {0} and {1}, inclusive.", 0, Int32.MaxValue - tryOffset));
114 if ((
long)handlerOffset + handlerLength > Int32.MaxValue)
116 throw new ArgumentOutOfRangeException(
"handlerLength",
string.Format(
"Valid values are between {0} and {1}, inclusive.", 0, Int32.MaxValue - handlerOffset));
121 if (kind == ExceptionHandlingClauseOptions.Clause && (exceptionTypeToken & 0x00FFFFFF) == 0)
123 throw new ArgumentException(
string.Format(
"Token {0:x} is not a valid Type token.", exceptionTypeToken),
"exceptionTypeToken");
126 if (!IsValidKind(kind))
128 throw new ArgumentOutOfRangeException(
"kind",
string.Format(
"Enum value was out of legal range."));
131 m_tryStartOffset = tryOffset;
132 m_tryEndOffset = tryOffset + tryLength;
133 m_filterOffset = filterOffset;
134 m_handlerStartOffset = handlerOffset;
135 m_handlerEndOffset = handlerOffset + handlerLength;
137 m_exceptionClass = exceptionTypeToken;
140 internal ExceptionHandler(
int tryStartOffset,
int tryEndOffset,
int filterOffset,
int handlerStartOffset,
int handlerEndOffset,
141 int kind,
int exceptionTypeToken)
143 Debug.Assert(tryStartOffset >= 0);
144 Debug.Assert(tryEndOffset >= 0);
145 Debug.Assert(filterOffset >= 0);
146 Debug.Assert(handlerStartOffset >= 0);
147 Debug.Assert(handlerEndOffset >= 0);
148 Debug.Assert(IsValidKind((ExceptionHandlingClauseOptions)kind));
149 Debug.Assert(kind != (
int)ExceptionHandlingClauseOptions.Clause || (exceptionTypeToken & 0x00FFFFFF) != 0);
151 m_tryStartOffset = tryStartOffset;
152 m_tryEndOffset = tryEndOffset;
153 m_filterOffset = filterOffset;
154 m_handlerStartOffset = handlerStartOffset;
155 m_handlerEndOffset = handlerEndOffset;
156 m_kind = (ExceptionHandlingClauseOptions)kind;
157 m_exceptionClass = exceptionTypeToken;
160 private static bool IsValidKind(ExceptionHandlingClauseOptions kind)
164 case ExceptionHandlingClauseOptions.Clause:
165 case ExceptionHandlingClauseOptions.Filter:
166 case ExceptionHandlingClauseOptions.Finally:
167 case ExceptionHandlingClauseOptions.Fault:
179 public override int GetHashCode()
181 return m_exceptionClass ^ m_tryStartOffset ^ m_tryEndOffset ^ m_filterOffset ^ m_handlerStartOffset ^ m_handlerEndOffset ^ (int)m_kind;
184 public override bool Equals(Object obj)
186 return obj is ExceptionHandler && Equals((ExceptionHandler)obj);
189 public bool Equals(ExceptionHandler other)
192 other.m_exceptionClass == m_exceptionClass &&
193 other.m_tryStartOffset == m_tryStartOffset &&
194 other.m_tryEndOffset == m_tryEndOffset &&
195 other.m_filterOffset == m_filterOffset &&
196 other.m_handlerStartOffset == m_handlerStartOffset &&
197 other.m_handlerEndOffset == m_handlerEndOffset &&
198 other.m_kind == m_kind;
201 public static bool operator ==(ExceptionHandler left, ExceptionHandler right)
203 return left.Equals(right);
206 public static bool operator !=(ExceptionHandler left, ExceptionHandler right)
208 return !left.Equals(right);