@@ -20,6 +20,18 @@ namespace Microsoft.Toolkit.Diagnostics
20
20
/// </summary>
21
21
public static partial class ThrowHelper
22
22
{
23
+ /// <summary>
24
+ /// Throws a new <see cref="ArrayTypeMismatchException"/>.
25
+ /// </summary>
26
+ /// <typeparam name="T">The type of expected result.</typeparam>
27
+ /// <exception cref="ArrayTypeMismatchException">Thrown with no parameters.</exception>
28
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
29
+ [ DoesNotReturn ]
30
+ public static T ThrowArrayTypeMismatchException < T > ( )
31
+ {
32
+ throw new ArrayTypeMismatchException ( ) ;
33
+ }
34
+
23
35
/// <summary>
24
36
/// Throws a new <see cref="ArrayTypeMismatchException"/>.
25
37
/// </summary>
@@ -47,6 +59,18 @@ public static T ThrowArrayTypeMismatchException<T>(string message, Exception inn
47
59
throw new ArrayTypeMismatchException ( message , innerException ) ;
48
60
}
49
61
62
+ /// <summary>
63
+ /// Throws a new <see cref="ArgumentException"/>.
64
+ /// </summary>
65
+ /// <typeparam name="T">The type of expected result.</typeparam>
66
+ /// <exception cref="ArgumentException">Thrown with no parameters.</exception>
67
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
68
+ [ DoesNotReturn ]
69
+ public static T ThrowArgumentException < T > ( )
70
+ {
71
+ throw new ArgumentException ( ) ;
72
+ }
73
+
50
74
/// <summary>
51
75
/// Throws a new <see cref="ArgumentException"/>.
52
76
/// </summary>
@@ -103,6 +127,18 @@ public static T ThrowArgumentException<T>(string name, string message, Exception
103
127
throw new ArgumentException ( message , name , innerException ) ;
104
128
}
105
129
130
+ /// <summary>
131
+ /// Throws a new <see cref="ArgumentNullException"/>.
132
+ /// </summary>
133
+ /// <typeparam name="T">The type of expected result.</typeparam>
134
+ /// <exception cref="ArgumentNullException">Thrown with no parameters.</exception>
135
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
136
+ [ DoesNotReturn ]
137
+ public static T ThrowArgumentNullException < T > ( )
138
+ {
139
+ throw new ArgumentNullException ( ) ;
140
+ }
141
+
106
142
/// <summary>
107
143
/// Throws a new <see cref="ArgumentNullException"/>.
108
144
/// </summary>
@@ -144,6 +180,18 @@ public static T ThrowArgumentNullException<T>(string name, string message)
144
180
throw new ArgumentNullException ( name , message ) ;
145
181
}
146
182
183
+ /// <summary>
184
+ /// Throws a new <see cref="ArgumentOutOfRangeException"/>.
185
+ /// </summary>
186
+ /// <typeparam name="T">The type of expected result.</typeparam>
187
+ /// <exception cref="ArgumentOutOfRangeException">Thrown with no parameters.</exception>
188
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
189
+ [ DoesNotReturn ]
190
+ public static T ThrowArgumentOutOfRangeException < T > ( )
191
+ {
192
+ throw new ArgumentOutOfRangeException ( ) ;
193
+ }
194
+
147
195
/// <summary>
148
196
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
149
197
/// </summary>
@@ -201,6 +249,18 @@ public static T ThrowArgumentOutOfRangeException<T>(string name, object value, s
201
249
}
202
250
203
251
#if ! NETSTANDARD1_4
252
+ /// <summary>
253
+ /// Throws a new <see cref="COMException"/>.
254
+ /// </summary>
255
+ /// <typeparam name="T">The type of expected result.</typeparam>
256
+ /// <exception cref="COMException">Thrown with no parameters.</exception>
257
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
258
+ [ DoesNotReturn ]
259
+ public static T ThrowCOMException < T > ( )
260
+ {
261
+ throw new COMException ( ) ;
262
+ }
263
+
204
264
/// <summary>
205
265
/// Throws a new <see cref="COMException"/>.
206
266
/// </summary>
@@ -242,6 +302,18 @@ public static T ThrowCOMException<T>(string message, int error)
242
302
throw new COMException ( message , error ) ;
243
303
}
244
304
305
+ /// <summary>
306
+ /// Throws a new <see cref="ExternalException"/>.
307
+ /// </summary>
308
+ /// <typeparam name="T">The type of expected result.</typeparam>
309
+ /// <exception cref="ExternalException">Thrown with no parameters.</exception>
310
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
311
+ [ DoesNotReturn ]
312
+ public static T ThrowExternalException < T > ( )
313
+ {
314
+ throw new ExternalException ( ) ;
315
+ }
316
+
245
317
/// <summary>
246
318
/// Throws a new <see cref="ExternalException"/>.
247
319
/// </summary>
@@ -284,6 +356,18 @@ public static T ThrowExternalException<T>(string message, int error)
284
356
}
285
357
#endif
286
358
359
+ /// <summary>
360
+ /// Throws a new <see cref="FormatException"/>.
361
+ /// </summary>
362
+ /// <typeparam name="T">The type of expected result.</typeparam>
363
+ /// <exception cref="FormatException">Thrown with no parameters.</exception>
364
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
365
+ [ DoesNotReturn ]
366
+ public static T ThrowFormatException < T > ( )
367
+ {
368
+ throw new FormatException ( ) ;
369
+ }
370
+
287
371
/// <summary>
288
372
/// Throws a new <see cref="FormatException"/>.
289
373
/// </summary>
@@ -312,6 +396,18 @@ public static T ThrowFormatException<T>(string message, Exception innerException
312
396
}
313
397
314
398
#if ! NETSTANDARD1_4
399
+ /// <summary>
400
+ /// Throws a new <see cref="InsufficientMemoryException"/>.
401
+ /// </summary>
402
+ /// <typeparam name="T">The type of expected result.</typeparam>
403
+ /// <exception cref="InsufficientMemoryException">Thrown with no parameters.</exception>
404
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
405
+ [ DoesNotReturn ]
406
+ public static T ThrowInsufficientMemoryException < T > ( )
407
+ {
408
+ throw new InsufficientMemoryException ( ) ;
409
+ }
410
+
315
411
/// <summary>
316
412
/// Throws a new <see cref="InsufficientMemoryException"/>.
317
413
/// </summary>
@@ -340,6 +436,18 @@ public static T ThrowInsufficientMemoryException<T>(string message, Exception in
340
436
}
341
437
#endif
342
438
439
+ /// <summary>
440
+ /// Throws a new <see cref="InvalidDataException"/>.
441
+ /// </summary>
442
+ /// <typeparam name="T">The type of expected result.</typeparam>
443
+ /// <exception cref="InvalidDataException">Thrown with no parameters.</exception>
444
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
445
+ [ DoesNotReturn ]
446
+ public static T ThrowInvalidDataException < T > ( )
447
+ {
448
+ throw new InvalidDataException ( ) ;
449
+ }
450
+
343
451
/// <summary>
344
452
/// Throws a new <see cref="InvalidDataException"/>.
345
453
/// </summary>
@@ -367,6 +475,18 @@ public static T ThrowInvalidDataException<T>(string message, Exception innerExce
367
475
throw new InvalidDataException ( message , innerException ) ;
368
476
}
369
477
478
+ /// <summary>
479
+ /// Throws a new <see cref="InvalidOperationException"/>.
480
+ /// </summary>
481
+ /// <typeparam name="T">The type of expected result.</typeparam>
482
+ /// <exception cref="InvalidOperationException">Thrown with no parameters.</exception>
483
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
484
+ [ DoesNotReturn ]
485
+ public static T ThrowInvalidOperationException < T > ( )
486
+ {
487
+ throw new InvalidOperationException ( ) ;
488
+ }
489
+
370
490
/// <summary>
371
491
/// Throws a new <see cref="InvalidOperationException"/>.
372
492
/// </summary>
@@ -394,6 +514,18 @@ public static T ThrowInvalidOperationException<T>(string message, Exception inne
394
514
throw new InvalidOperationException ( message , innerException ) ;
395
515
}
396
516
517
+ /// <summary>
518
+ /// Throws a new <see cref="LockRecursionException"/>.
519
+ /// </summary>
520
+ /// <typeparam name="T">The type of expected result.</typeparam>
521
+ /// <exception cref="LockRecursionException">Thrown with no parameters.</exception>
522
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
523
+ [ DoesNotReturn ]
524
+ public static T ThrowLockRecursionException < T > ( )
525
+ {
526
+ throw new LockRecursionException ( ) ;
527
+ }
528
+
397
529
/// <summary>
398
530
/// Throws a new <see cref="LockRecursionException"/>.
399
531
/// </summary>
@@ -421,6 +553,18 @@ public static T ThrowLockRecursionException<T>(string message, Exception innerEx
421
553
throw new LockRecursionException ( message , innerException ) ;
422
554
}
423
555
556
+ /// <summary>
557
+ /// Throws a new <see cref="MissingFieldException"/>.
558
+ /// </summary>
559
+ /// <typeparam name="T">The type of expected result.</typeparam>
560
+ /// <exception cref="MissingFieldException">Thrown with no parameters.</exception>
561
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
562
+ [ DoesNotReturn ]
563
+ public static T ThrowMissingFieldException < T > ( )
564
+ {
565
+ throw new MissingFieldException ( ) ;
566
+ }
567
+
424
568
/// <summary>
425
569
/// Throws a new <see cref="MissingFieldException"/>.
426
570
/// </summary>
@@ -464,6 +608,18 @@ public static T ThrowMissingFieldException<T>(string className, string fieldName
464
608
}
465
609
#endif
466
610
611
+ /// <summary>
612
+ /// Throws a new <see cref="MissingMemberException"/>.
613
+ /// </summary>
614
+ /// <typeparam name="T">The type of expected result.</typeparam>
615
+ /// <exception cref="MissingMemberException">Thrown with no parameters.</exception>
616
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
617
+ [ DoesNotReturn ]
618
+ public static T ThrowMissingMemberException < T > ( )
619
+ {
620
+ throw new MissingMemberException ( ) ;
621
+ }
622
+
467
623
/// <summary>
468
624
/// Throws a new <see cref="MissingMemberException"/>.
469
625
/// </summary>
@@ -507,6 +663,18 @@ public static T ThrowMissingMemberException<T>(string className, string memberNa
507
663
}
508
664
#endif
509
665
666
+ /// <summary>
667
+ /// Throws a new <see cref="MissingMethodException"/>.
668
+ /// </summary>
669
+ /// <typeparam name="T">The type of expected result.</typeparam>
670
+ /// <exception cref="MissingMethodException">Thrown with no parameters.</exception>
671
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
672
+ [ DoesNotReturn ]
673
+ public static T ThrowMissingMethodException < T > ( )
674
+ {
675
+ throw new MissingMethodException ( ) ;
676
+ }
677
+
510
678
/// <summary>
511
679
/// Throws a new <see cref="MissingMethodException"/>.
512
680
/// </summary>
@@ -550,6 +718,18 @@ public static T ThrowMissingMethodException<T>(string className, string methodNa
550
718
}
551
719
#endif
552
720
721
+ /// <summary>
722
+ /// Throws a new <see cref="NotSupportedException"/>.
723
+ /// </summary>
724
+ /// <typeparam name="T">The type of expected result.</typeparam>
725
+ /// <exception cref="NotSupportedException">Thrown with no parameters.</exception>
726
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
727
+ [ DoesNotReturn ]
728
+ public static T ThrowNotSupportedException < T > ( )
729
+ {
730
+ throw new NotSupportedException ( ) ;
731
+ }
732
+
553
733
/// <summary>
554
734
/// Throws a new <see cref="NotSupportedException"/>.
555
735
/// </summary>
@@ -618,6 +798,18 @@ public static T ThrowObjectDisposedException<T>(string objectName, string messag
618
798
throw new ObjectDisposedException ( objectName , message ) ;
619
799
}
620
800
801
+ /// <summary>
802
+ /// Throws a new <see cref="OperationCanceledException"/>.
803
+ /// </summary>
804
+ /// <typeparam name="T">The type of expected result.</typeparam>
805
+ /// <exception cref="OperationCanceledException">Thrown with no parameters.</exception>
806
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
807
+ [ DoesNotReturn ]
808
+ public static T ThrowOperationCanceledException < T > ( )
809
+ {
810
+ throw new OperationCanceledException ( ) ;
811
+ }
812
+
621
813
/// <summary>
622
814
/// Throws a new <see cref="OperationCanceledException"/>.
623
815
/// </summary>
@@ -687,6 +879,18 @@ public static T ThrowOperationCanceledException<T>(string message, Exception inn
687
879
throw new OperationCanceledException ( message , innerException , token ) ;
688
880
}
689
881
882
+ /// <summary>
883
+ /// Throws a new <see cref="PlatformNotSupportedException"/>.
884
+ /// </summary>
885
+ /// <typeparam name="T">The type of expected result.</typeparam>
886
+ /// <exception cref="PlatformNotSupportedException">Thrown with no parameters.</exception>
887
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
888
+ [ DoesNotReturn ]
889
+ public static T ThrowPlatformNotSupportedException < T > ( )
890
+ {
891
+ throw new PlatformNotSupportedException ( ) ;
892
+ }
893
+
690
894
/// <summary>
691
895
/// Throws a new <see cref="PlatformNotSupportedException"/>.
692
896
/// </summary>
@@ -714,6 +918,18 @@ public static T ThrowPlatformNotSupportedException<T>(string message, Exception
714
918
throw new PlatformNotSupportedException ( message , innerException ) ;
715
919
}
716
920
921
+ /// <summary>
922
+ /// Throws a new <see cref="SynchronizationLockException"/>.
923
+ /// </summary>
924
+ /// <typeparam name="T">The type of expected result.</typeparam>
925
+ /// <exception cref="SynchronizationLockException">Thrown with no parameters.</exception>
926
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
927
+ [ DoesNotReturn ]
928
+ public static T ThrowSynchronizationLockException < T > ( )
929
+ {
930
+ throw new SynchronizationLockException ( ) ;
931
+ }
932
+
717
933
/// <summary>
718
934
/// Throws a new <see cref="SynchronizationLockException"/>.
719
935
/// </summary>
@@ -741,6 +957,18 @@ public static T ThrowSynchronizationLockException<T>(string message, Exception i
741
957
throw new SynchronizationLockException ( message , innerException ) ;
742
958
}
743
959
960
+ /// <summary>
961
+ /// Throws a new <see cref="TimeoutException"/>.
962
+ /// </summary>
963
+ /// <typeparam name="T">The type of expected result.</typeparam>
964
+ /// <exception cref="TimeoutException">Thrown with no parameters.</exception>
965
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
966
+ [ DoesNotReturn ]
967
+ public static T ThrowTimeoutException < T > ( )
968
+ {
969
+ throw new TimeoutException ( ) ;
970
+ }
971
+
744
972
/// <summary>
745
973
/// Throws a new <see cref="TimeoutException"/>.
746
974
/// </summary>
@@ -768,6 +996,18 @@ public static T ThrowTimeoutException<T>(string message, Exception innerExceptio
768
996
throw new TimeoutException ( message , innerException ) ;
769
997
}
770
998
999
+ /// <summary>
1000
+ /// Throws a new <see cref="UnauthorizedAccessException"/>.
1001
+ /// </summary>
1002
+ /// <typeparam name="T">The type of expected result.</typeparam>
1003
+ /// <exception cref="UnauthorizedAccessException">Thrown with no parameters.</exception>
1004
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
1005
+ [ DoesNotReturn ]
1006
+ public static T ThrowUnauthorizedAccessException < T > ( )
1007
+ {
1008
+ throw new UnauthorizedAccessException ( ) ;
1009
+ }
1010
+
771
1011
/// <summary>
772
1012
/// Throws a new <see cref="UnauthorizedAccessException"/>.
773
1013
/// </summary>
@@ -795,6 +1035,18 @@ public static T ThrowUnauthorizedAccessException<T>(string message, Exception in
795
1035
throw new UnauthorizedAccessException ( message , innerException ) ;
796
1036
}
797
1037
1038
+ /// <summary>
1039
+ /// Throws a new <see cref="Win32Exception"/>.
1040
+ /// </summary>
1041
+ /// <typeparam name="T">The type of expected result.</typeparam>
1042
+ /// <exception cref="Win32Exception">Thrown with no parameters.</exception>
1043
+ /// <returns>This method always throws, so it actually never returns a value.</returns>
1044
+ [ DoesNotReturn ]
1045
+ public static T ThrowWin32Exception < T > ( )
1046
+ {
1047
+ throw new Win32Exception ( ) ;
1048
+ }
1049
+
798
1050
/// <summary>
799
1051
/// Throws a new <see cref="Win32Exception"/>.
800
1052
/// </summary>
0 commit comments