@@ -518,17 +518,9 @@ unittest
518
518
// Testing object conversions
519
519
class A {} class B : A {} class C : A {}
520
520
A a1 = new A, a2 = new B, a3 = new C;
521
- assert (to! (B)(a2) is a2);
522
- assert (to! (C)(a3) is a3);
523
- try
524
- {
525
- to! (B)(a3);
526
- assert (false );
527
- }
528
- catch (ConvException e)
529
- {
530
- // writeln(e);
531
- }
521
+ assert (to! B(a2) is a2);
522
+ assert (to! C(a3) is a3);
523
+ assertThrown! ConvException(to! B(a3));
532
524
}
533
525
534
526
/**
@@ -1712,17 +1704,10 @@ unittest
1712
1704
// boundary values
1713
1705
foreach (Int; TypeTuple! (byte , ubyte , short , ushort , int , uint ))
1714
1706
{
1715
- try
1716
- {
1717
- assert (roundTo! Int(Int.min - 0.4L ) == Int.min);
1718
- assert (roundTo! Int(Int.max + 0.4L ) == Int.max);
1719
- }
1720
- catch (ConvOverflowException e)
1721
- {
1722
- assert (0 );
1723
- }
1724
- try { roundTo! Int(Int.min - 0.5L ); assert (0 ); } catch (ConvOverflowException e) {}
1725
- try { roundTo! Int(Int.max + 0.5L ); assert (0 ); } catch (ConvOverflowException e) {}
1707
+ assert (roundTo! Int(Int.min - 0.4L ) == Int.min);
1708
+ assert (roundTo! Int(Int.max + 0.4L ) == Int.max);
1709
+ assertThrown! ConvOverflowException(roundTo! Int(Int.min - 0.5L ));
1710
+ assertThrown! ConvOverflowException(roundTo! Int(Int.max + 0.5L ));
1726
1711
}
1727
1712
}
1728
1713
@@ -2500,14 +2485,7 @@ unittest
2500
2485
assert (to! F(" y" w) == F.y);
2501
2486
assert (to! F(" z" d) == F.z);
2502
2487
2503
- try
2504
- {
2505
- to! E(" d" );
2506
- assert (0 );
2507
- }
2508
- catch (ConvException e)
2509
- {
2510
- }
2488
+ assertThrown! ConvException(to! E(" d" ));
2511
2489
}
2512
2490
2513
2491
version (none ) // TODO: BUG4744
@@ -2873,16 +2851,7 @@ unittest
2873
2851
assert (to! string (f) == to! string (float .nan));
2874
2852
assert (isnan(f));
2875
2853
2876
- bool ok = false ;
2877
- try
2878
- {
2879
- to! float (" \x00 " );
2880
- }
2881
- catch (ConvException e)
2882
- {
2883
- ok = true ;
2884
- }
2885
- assert (ok);
2854
+ assertThrown! ConvException(to! float (" \x00 " ));
2886
2855
}
2887
2856
2888
2857
/*
@@ -2936,16 +2905,7 @@ unittest
2936
2905
assert (to! string (d) == to! string (double .nan));
2937
2906
assert (isnan(d));
2938
2907
2939
- bool ok = false ;
2940
- try
2941
- {
2942
- to! double (" \x00 " );
2943
- }
2944
- catch (ConvException e)
2945
- {
2946
- ok = true ;
2947
- }
2948
- assert (ok);
2908
+ assertThrown! ConvException(to! double (" \x00 " ));
2949
2909
}
2950
2910
2951
2911
/*
@@ -3004,16 +2964,7 @@ unittest
3004
2964
assert (to! string (r) == to! string (real .nan));
3005
2965
assert (isnan(r));
3006
2966
3007
- bool ok = false ;
3008
- try
3009
- {
3010
- to! real (" \x00 " );
3011
- }
3012
- catch (ConvException e)
3013
- {
3014
- ok = true ;
3015
- }
3016
- assert (ok);
2967
+ assertThrown! ConvException(to! real (" \x00 " ));
3017
2968
}
3018
2969
3019
2970
unittest
@@ -3153,12 +3104,7 @@ unittest
3153
3104
3154
3105
assert (to! bool (" TruE" ) == true );
3155
3106
assert (to! bool (" faLse" d) == false );
3156
- try
3157
- {
3158
- to! bool (" maybe" );
3159
- assert (false );
3160
- }
3161
- catch (ConvException e) { }
3107
+ assertThrown! ConvException(to! bool (" maybe" ));
3162
3108
3163
3109
auto t = " TrueType" ;
3164
3110
assert (parse! bool (t) == true );
@@ -3169,15 +3115,8 @@ unittest
3169
3115
assert (f == " killer whale" d);
3170
3116
3171
3117
auto m = " maybe" ;
3172
- try
3173
- {
3174
- parse! bool (m);
3175
- assert (false );
3176
- }
3177
- catch (ConvException e)
3178
- {
3179
- assert (m == " maybe" ); // m shouldn't change on failure
3180
- }
3118
+ assertThrown! ConvException(parse! bool (m));
3119
+ assert (m == " maybe" ); // m shouldn't change on failure
3181
3120
3182
3121
auto b = parse! (const (bool ))(" true" );
3183
3122
assert (b == true );
0 commit comments