@@ -262,22 +262,12 @@ TEST_GROUP(OutOfMemoryTestsForOperatorNew)
262
262
263
263
TEST (OutOfMemoryTestsForOperatorNew, FailingNewOperatorThrowsAnExceptionWhenUsingStdCppNew)
264
264
{
265
- try {
266
- new char ;
267
- FAIL (" Should have thrown an exception!" )
268
- }
269
- catch (std::bad_alloc&) {
270
- }
265
+ CHECK_THROWS (std::bad_alloc, new char );
271
266
}
272
267
273
268
TEST (OutOfMemoryTestsForOperatorNew, FailingNewArrayOperatorThrowsAnExceptionWhenUsingStdCppNew)
274
269
{
275
- try {
276
- new char [10 ];
277
- FAIL (" Should have thrown an exception!" )
278
- }
279
- catch (std::bad_alloc&) {
280
- }
270
+ CHECK_THROWS (std::bad_alloc, new char [10 ]);
281
271
}
282
272
283
273
class ClassThatThrowsAnExceptionInTheConstructor
@@ -294,18 +284,12 @@ TEST_GROUP(TestForExceptionsInConstructor)
294
284
295
285
TEST (TestForExceptionsInConstructor,ConstructorThrowsAnException)
296
286
{
297
- try {
298
- new ClassThatThrowsAnExceptionInTheConstructor ();
299
- }catch (...){
300
- }
287
+ CHECK_THROWS (int , new ClassThatThrowsAnExceptionInTheConstructor);
301
288
}
302
289
303
290
TEST (TestForExceptionsInConstructor,ConstructorThrowsAnExceptionAllocatedAsArray)
304
291
{
305
- try {
306
- new ClassThatThrowsAnExceptionInTheConstructor[10 ];
307
- }catch (...){
308
- }
292
+ CHECK_THROWS (int , new ClassThatThrowsAnExceptionInTheConstructor[10 ]);
309
293
}
310
294
311
295
#else
@@ -356,22 +340,12 @@ static char* some_memory;
356
340
357
341
TEST (OutOfMemoryTestsForOperatorNew, FailingNewOperatorThrowsAnExceptionWhenUsingStdCppNewWithoutOverride)
358
342
{
359
- try {
360
- some_memory = new char ;
361
- FAIL (" Should have thrown an exception!" )
362
- }
363
- catch (std::bad_alloc&) {
364
- }
343
+ CHECK_THROWS (std::bad_alloc, some_memory = new char );
365
344
}
366
345
367
346
TEST (OutOfMemoryTestsForOperatorNew, FailingNewArrayOperatorThrowsAnExceptionWhenUsingStdCppNewWithoutOverride)
368
347
{
369
- try {
370
- some_memory = new char [10 ];
371
- FAIL (" Should have thrown an exception!" )
372
- }
373
- catch (std::bad_alloc&) {
374
- }
348
+ CHECK_THROWS (std::bad_alloc, some_memory = new char [10 ]);
375
349
}
376
350
377
351
TEST (OutOfMemoryTestsForOperatorNew, FailingNewOperatorReturnsNullWithoutOverride)
0 commit comments