| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics.CodeAnalysis; |
| | | 5 | | using System.Reflection.Metadata; |
| | | 6 | | using System.Reflection.Metadata.Ecma335; |
| | | 7 | | |
| | | 8 | | namespace System.Reflection |
| | | 9 | | { |
| | | 10 | | // This file defines an internal class used to throw exceptions. The main purpose is to reduce code size. |
| | | 11 | | // Also it improves the likelihood that callers will be inlined. |
| | | 12 | | internal static class Throw |
| | | 13 | | { |
| | | 14 | | [DoesNotReturn] |
| | | 15 | | internal static void InvalidCast() |
| | 0 | 16 | | { |
| | 0 | 17 | | throw new InvalidCastException(); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | [DoesNotReturn] |
| | | 21 | | internal static void InvalidArgument(string message, string parameterName) |
| | 0 | 22 | | { |
| | 0 | 23 | | throw new ArgumentException(message, parameterName); |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | [DoesNotReturn] |
| | | 27 | | internal static void InvalidArgument_OffsetForVirtualHeapHandle() |
| | 0 | 28 | | { |
| | 0 | 29 | | throw new ArgumentException(SR.CantGetOffsetForVirtualHeapHandle, "handle"); |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | [DoesNotReturn] |
| | | 33 | | internal static Exception InvalidArgument_UnexpectedHandleKind(HandleKind kind) |
| | 0 | 34 | | { |
| | 0 | 35 | | throw new ArgumentException(SR.Format(SR.UnexpectedHandleKind, kind)); |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | [DoesNotReturn] |
| | | 39 | | internal static Exception InvalidArgument_Handle(string parameterName) |
| | 0 | 40 | | { |
| | 0 | 41 | | throw new ArgumentException(SR.InvalidHandle, parameterName); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | [DoesNotReturn] |
| | | 45 | | internal static void SignatureNotVarArg() |
| | 0 | 46 | | { |
| | 0 | 47 | | throw new InvalidOperationException(SR.SignatureNotVarArg); |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | [DoesNotReturn] |
| | | 51 | | internal static void ControlFlowBuilderNotAvailable() |
| | 0 | 52 | | { |
| | 0 | 53 | | throw new InvalidOperationException(SR.ControlFlowBuilderNotAvailable); |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | [DoesNotReturn] |
| | | 57 | | internal static void InvalidOperationBuilderAlreadyLinked() |
| | 0 | 58 | | { |
| | 0 | 59 | | throw new InvalidOperationException(SR.BuilderAlreadyLinked); |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | [DoesNotReturn] |
| | | 63 | | internal static void InvalidOperation(string message) |
| | 0 | 64 | | { |
| | 0 | 65 | | throw new InvalidOperationException(message); |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | [DoesNotReturn] |
| | | 69 | | internal static void InvalidOperation_LabelNotMarked(int id) |
| | 0 | 70 | | { |
| | 0 | 71 | | throw new InvalidOperationException(SR.Format(SR.LabelNotMarked, id)); |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | [DoesNotReturn] |
| | | 75 | | internal static void LabelDoesntBelongToBuilder(string parameterName) |
| | 0 | 76 | | { |
| | 0 | 77 | | throw new ArgumentException(SR.LabelDoesntBelongToBuilder, parameterName); |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | [DoesNotReturn] |
| | | 81 | | internal static void HeapHandleRequired() |
| | 0 | 82 | | { |
| | 0 | 83 | | throw new ArgumentException(SR.NotMetadataHeapHandle, "handle"); |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | [DoesNotReturn] |
| | | 87 | | internal static void EntityOrUserStringHandleRequired() |
| | 0 | 88 | | { |
| | 0 | 89 | | throw new ArgumentException(SR.NotMetadataTableOrUserStringHandle, "handle"); |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | [DoesNotReturn] |
| | | 93 | | internal static void InvalidToken() |
| | 0 | 94 | | { |
| | 0 | 95 | | throw new ArgumentException(SR.InvalidToken, "token"); |
| | | 96 | | } |
| | | 97 | | |
| | | 98 | | [DoesNotReturn] |
| | | 99 | | internal static void ArgumentNull(string parameterName) |
| | 0 | 100 | | { |
| | 0 | 101 | | throw new ArgumentNullException(parameterName); |
| | | 102 | | } |
| | | 103 | | |
| | | 104 | | [DoesNotReturn] |
| | | 105 | | internal static void ArgumentEmptyString(string parameterName) |
| | 0 | 106 | | { |
| | 0 | 107 | | throw new ArgumentException(SR.ExpectedNonEmptyString, parameterName); |
| | | 108 | | } |
| | | 109 | | |
| | | 110 | | [DoesNotReturn] |
| | | 111 | | internal static void ArgumentEmptyArray(string parameterName) |
| | 0 | 112 | | { |
| | 0 | 113 | | throw new ArgumentException(SR.ExpectedNonEmptyArray, parameterName); |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | [DoesNotReturn] |
| | | 117 | | internal static void ArgumentOutOfRange(string parameterName) |
| | 0 | 118 | | { |
| | 0 | 119 | | throw new ArgumentOutOfRangeException(parameterName); |
| | | 120 | | } |
| | | 121 | | |
| | | 122 | | [DoesNotReturn] |
| | | 123 | | internal static void ArgumentOutOfRange(string parameterName, string message) |
| | 0 | 124 | | { |
| | 0 | 125 | | throw new ArgumentOutOfRangeException(parameterName, message); |
| | | 126 | | } |
| | | 127 | | |
| | | 128 | | [DoesNotReturn] |
| | | 129 | | internal static void BlobTooLarge(string parameterName) |
| | 0 | 130 | | { |
| | 0 | 131 | | throw new ArgumentOutOfRangeException(parameterName, SR.BlobTooLarge); |
| | | 132 | | } |
| | | 133 | | |
| | | 134 | | [DoesNotReturn] |
| | | 135 | | internal static void IndexOutOfRange() |
| | 0 | 136 | | { |
| | 0 | 137 | | throw new ArgumentOutOfRangeException("index"); |
| | | 138 | | } |
| | | 139 | | |
| | | 140 | | [DoesNotReturn] |
| | | 141 | | internal static void TableIndexOutOfRange() |
| | 0 | 142 | | { |
| | 0 | 143 | | throw new ArgumentOutOfRangeException("tableIndex"); |
| | | 144 | | } |
| | | 145 | | |
| | | 146 | | [DoesNotReturn] |
| | | 147 | | internal static void ValueArgumentOutOfRange() |
| | 0 | 148 | | { |
| | 0 | 149 | | throw new ArgumentOutOfRangeException("value"); |
| | | 150 | | } |
| | | 151 | | |
| | | 152 | | [DoesNotReturn] |
| | | 153 | | internal static void OutOfBounds() |
| | 0 | 154 | | { |
| | 0 | 155 | | throw new BadImageFormatException(SR.OutOfBoundsRead); |
| | | 156 | | } |
| | | 157 | | |
| | | 158 | | [DoesNotReturn] |
| | | 159 | | internal static void WriteOutOfBounds() |
| | 0 | 160 | | { |
| | 0 | 161 | | throw new InvalidOperationException(SR.OutOfBoundsWrite); |
| | | 162 | | } |
| | | 163 | | |
| | | 164 | | [DoesNotReturn] |
| | | 165 | | internal static void InvalidCodedIndex() |
| | 0 | 166 | | { |
| | 0 | 167 | | throw new BadImageFormatException(SR.InvalidCodedIndex); |
| | | 168 | | } |
| | | 169 | | |
| | | 170 | | [DoesNotReturn] |
| | | 171 | | internal static void InvalidHandle() |
| | 0 | 172 | | { |
| | 0 | 173 | | throw new BadImageFormatException(SR.InvalidHandle); |
| | | 174 | | } |
| | | 175 | | |
| | | 176 | | [DoesNotReturn] |
| | | 177 | | internal static void InvalidCompressedInteger() |
| | 0 | 178 | | { |
| | 0 | 179 | | throw new BadImageFormatException(SR.InvalidCompressedInteger); |
| | | 180 | | } |
| | | 181 | | |
| | | 182 | | [DoesNotReturn] |
| | | 183 | | internal static void InvalidSerializedString() |
| | 0 | 184 | | { |
| | 0 | 185 | | throw new BadImageFormatException(SR.InvalidSerializedString); |
| | | 186 | | } |
| | | 187 | | |
| | | 188 | | [DoesNotReturn] |
| | | 189 | | internal static void ImageTooSmall() |
| | 0 | 190 | | { |
| | 0 | 191 | | throw new BadImageFormatException(SR.ImageTooSmall); |
| | | 192 | | } |
| | | 193 | | |
| | | 194 | | [DoesNotReturn] |
| | | 195 | | internal static void ImageTooSmallOrContainsInvalidOffsetOrCount() |
| | 0 | 196 | | { |
| | 0 | 197 | | throw new BadImageFormatException(SR.ImageTooSmallOrContainsInvalidOffsetOrCount); |
| | | 198 | | } |
| | | 199 | | |
| | | 200 | | [DoesNotReturn] |
| | | 201 | | internal static void ReferenceOverflow() |
| | 0 | 202 | | { |
| | 0 | 203 | | throw new BadImageFormatException(SR.RowIdOrHeapOffsetTooLarge); |
| | | 204 | | } |
| | | 205 | | |
| | | 206 | | [DoesNotReturn] |
| | | 207 | | internal static void TableNotSorted(TableIndex tableIndex) |
| | 0 | 208 | | { |
| | 0 | 209 | | throw new BadImageFormatException(SR.Format(SR.MetadataTableNotSorted, tableIndex)); |
| | | 210 | | } |
| | | 211 | | |
| | | 212 | | [DoesNotReturn] |
| | | 213 | | internal static void InvalidOperation_TableNotSorted(TableIndex tableIndex) |
| | 0 | 214 | | { |
| | 0 | 215 | | throw new InvalidOperationException(SR.Format(SR.MetadataTableNotSorted, tableIndex)); |
| | | 216 | | } |
| | | 217 | | |
| | | 218 | | [DoesNotReturn] |
| | | 219 | | internal static void InvalidOperation_PEImageNotAvailable() |
| | 0 | 220 | | { |
| | 0 | 221 | | throw new InvalidOperationException(SR.PEImageNotAvailable); |
| | | 222 | | } |
| | | 223 | | |
| | | 224 | | [DoesNotReturn] |
| | | 225 | | internal static void TooManySubnamespaces() |
| | 0 | 226 | | { |
| | 0 | 227 | | throw new BadImageFormatException(SR.TooManySubnamespaces); |
| | | 228 | | } |
| | | 229 | | |
| | | 230 | | [DoesNotReturn] |
| | | 231 | | internal static void ValueOverflow() |
| | 0 | 232 | | { |
| | 0 | 233 | | throw new BadImageFormatException(SR.ValueTooLarge); |
| | | 234 | | } |
| | | 235 | | |
| | | 236 | | [DoesNotReturn] |
| | | 237 | | internal static void SequencePointValueOutOfRange() |
| | 0 | 238 | | { |
| | 0 | 239 | | throw new BadImageFormatException(SR.SequencePointValueOutOfRange); |
| | | 240 | | } |
| | | 241 | | |
| | | 242 | | [DoesNotReturn] |
| | | 243 | | internal static void HeapSizeLimitExceeded(HeapIndex heap) |
| | 0 | 244 | | { |
| | 0 | 245 | | throw new ImageFormatLimitationException(SR.Format(SR.HeapSizeLimitExceeded, heap)); |
| | | 246 | | } |
| | | 247 | | |
| | | 248 | | [DoesNotReturn] |
| | | 249 | | internal static void PEReaderDisposed() |
| | 0 | 250 | | { |
| | 0 | 251 | | throw new ObjectDisposedException(nameof(PortableExecutable.PEReader)); |
| | | 252 | | } |
| | | 253 | | } |
| | | 254 | | } |
| | | 255 | | |